# The basics of using SSGen
# (c) theokrueger 2024
# GPL-3.0 Licensed
# Intro
- h1: Variables and !DEF
- p: >
SSGen allows simple variable declaration and substitution.
Define a variable using the !DEF
directive, and use it with brace substitution.
- p: >
Variables in SSGen are scoped, meaning that they only exist in the node they are defined in.
Children inherit the variables of their parents. If a variable is declared with the same name as another, the most recently declared variable will be used.
Once the scope is left and the newer declaration is released, the older declaration will become the current value.
- p: >
In other words: Variables work like they do in most programming languages.
You will find using them very intuitive.
---
# Example
- br: ''
- p: Define and use a variable like so
- span:
_class: two-column-grid-with-spacer
yaml:
- !DEF [NAMED_CODE_NAME, "input_directory/index.page"]
- !DEF
- NAMED_CODE_CONTENT
- |
\# Syntax: !DEF [name, value]
!DEF [content, "Paragraph contents"]
html:
body:
h1: Title
# Substitute variables into text using \\\{variable_name}
p: '\\\{content}'
- !INCLUDE /blocks/named-code.block
br: ''
html:
- !DEF [NAMED_CODE_NAME, "output_directory/index.html"]
- !DEF
- NAMED_CODE_CONTENT
- |
<html>
<body>
<h1>Title</h1>
<p>Paragraph Contents</p>
</body>
</html>
- !INCLUDE /blocks/named-code.block
# Clarification
- p: If starting a string off with a variable substitution, the string should be single or double quoted.
- p:
- 'Braces can be escaped by using a backslash: '
- code: 'p: "\\\{escaped}"'
- ' becomes '
- code: '<p>\{escaped}</p>'