<< mau:aux/included-text-b.mauAdvanced include
Nested include
When Mau includes another Mau file, the content is parsed and then added to the current AST. This means that you can include a file that includes another file.
The following example will use the files aux/included-text-a.mau and aux/included-text-b.mau that contain the following code
=== Included content
This is a file with *Mau syntax*.Both files are reachable by the tool that builds the website using that path.
Include loops
Mau detects include loops such as
- A file includes itself.
- File A includes file B which includes file A.
If such a case occurs, Mau will stop processing the file and signal the issue.
Included files and environment
Included files are parsed using the current environment, and this is inherited at every level of a nested inclusion.
The following example will use the files aux/included-text-env-a.mau and aux/included-text-env-b.mau that contain the following code
The answer will be: {answer}
<< mau:aux/included-text-env-b.mauThe answer is: {answer}Both files are reachable by the tool that builds the website using that path.
:answer:42
<< mau:aux/included-text-env-a.mauThe answer will be: 42
The answer is: 42
Passing new variables to included files
Mau allows you to pass new variables to an included file, in a way similar to a function call. To do that, use the syntax call:NAME=VALUE in the include arguments. The variables will become part of the included file environment, and thus will be automatically passed to any nested inclusion.
The following example will use the files aux/included-text-env-a.mau and aux/included-text-env-b.mau seen above.
<< mau:aux/included-text-env-a.mau, call:answer=42The answer will be: 42
The answer is: 42
Prevent the environment from being passed
You can prevent the environment to the automatically passed to the included file using pass_environment=false.
The following example will use the file aux/included-text-env-a.mau seen above. The following code will fail with an error Parser error: Variable 'answer' has not been defined. in aux/included-text-env-a.mau.
:answer:42
<< mau:aux/included-text-env-a.mau, pass_environment=falseEnvironment and call arguments
When the option pass_environment=false is set, the included piece of Mau text still receives all the arguments marked with the prefix call:.
In the following example, the included text will not see the variable answer, but will see a variable called value.
:answer:42
<< mau:aux/included-text-env-a.mau, pass_environment=false