neutralts::bif

Module parse_bif_include

Source
Expand description

§{:include; … :}

Include and usually parse any file, usually a template.

{:include; filename :}

{:include; template.ntpl :}

§Modifiers:

{:!include; ... :}
{:^include; ... :}

§Modifier: ! (not)

The “not” modifier prevents the file from being reparse if it has already been parsed.

Assuming that the content of file.ntpl is simply the word “Hello”:

{:include; file.ntpl :}
...
{:include; file.ntpl :}

Output:

Hello
Hello

With “not”:

{:include; file.ntpl :}
...
{:!include; file.ntpl :}

Output:

Hello

The following produces the same result as above:

{:!include; file.ntpl :}
...
{:!include; file.ntpl :}

Or can the parse be forced:

{:!include; file.ntpl :}
...
{:include; file.ntpl :}

Output:

Hello
Hello

§Flags

{:include; {:flg; require noparse safe :} >> ... :}

§Flag: require

By default, no error will occur if the file to include does not exist, unless the “require” flag is set.

{:include; {:flg; require :} >> file.ntpl :}

§Flag: noparse

The “noparse” flag prevents the file to be included from being parsed.

{:include; {:flg; noparse :} >> file.css :}

§Flag: safe

Encoding all, safe implies noparse.

{:include; {:flg; safe :} >> file.txt :}

§Dynamic evaluation

The following will produce an error:

{:include; {:;varname:} :}

For safety reasons, when evaluating the complete variable it is necessary to use “allow”:

{:include; {:allow; allowed-words-list >> {:;varname:} :} :}
{:include; {:!allow; traversal >> {:;varname:} :} :}

In any case, you must use “allow” on any variable that comes from the context. See the “allow” and “declare” bifs for more details.

§Relative to current file path

When creating a web application, we’ll know where the files are located, so we can do:

{:include; /path/to/tpl/template.ntpl :}

We can use relative paths to the currently included file with the “#” symbol:

{:include; #/snippets.ntpl :}

When using “#” inside /path/to/tpl/template.ntpl, it becomes:

{:include; /path/to/tpl/snippets.ntpl :}

In this way, we can create utilities without knowing the directory structure.