added extends and child commands to readme

This commit is contained in:
overflowerror 2021-06-09 20:01:58 +02:00
parent 487442b05d
commit 0e8ba48a9e

View file

@ -103,12 +103,14 @@ Structure blocks have the following syntax:
{# [structure command] ( [parameters] ) #} {# [structure command] ( [parameters] ) #}
``` ```
At the moment there is only one structure command implemented. The following structure commands are implemented:
## Render ## Render
Using the render command, a another template can be included at the current position. The first parameter is the name of the template to be included as a string. All following parameters will be used as template parameters. Using the render command, a another template can be included at the current position. The first parameter is the name of the template to be included as a string. All following parameters will be used as template parameters.
Note: The `render` command can only be used in the main section.
Example: Example:
``` ```
{# render("templates/index.html.templ", "Page Title", userArray, userArrayLength) #} {# render("templates/index.html.templ", "Page Title", userArray, userArrayLength) #}
@ -116,7 +118,27 @@ Example:
All used variables have to be declared (for example as template parameters or local variables of statement blocks). All used variables have to be declared (for example as template parameters or local variables of statement blocks).
### Complete Example ## Extends
`extends` can be used to extend an existing abstract template (see "Child"). This is useful for splitting the page layout and the content into multiple files.
Similar to `render` command the arguments are the name of the parent template followed by the template parameters of the parent (only parameters of the current template are allowed as variables).
Note: The `extends` command can only be used in the meta section.
```
{# extends("templates/layout.html.templ", "Page Title") #}
```
## Child
`child` is used in the main section of a template to indicate where the child template should be rendered. Using this command will implicitly set the template to abstract.
```
{# child() #}
```
### Basic Example
``` ```
{% #include "entities.h" %} {% #include "entities.h" %}
@ -138,6 +160,8 @@ All used variables have to be declared (for example as template parameters or lo
</html> </html>
``` ```
For an example using structure blocks, please take a look at the provided demo files.
## Translating Template ## Translating Template
To translate a template call the `parvical` binary using the template file as it's argument. The generated C code will be outputed to `stdout`. To translate a template call the `parvical` binary using the template file as it's argument. The generated C code will be outputed to `stdout`.