neutralts::bif

Module parse_bif_var

Source
Expand description

§{:; … :} (var)

Output var value.

{:;varname:}
{:;array->key:}

§Modifiers:

{:^;varname:}
{:&;varname:}
{:!;varname:}

§Modifier: ^ (upline)

Assuming that the value of “varname” is “value”:

<div></div>

{:;varname:}

<div></div>

{:^;varname:}

Output:

<div></div>

value

<div></div>value

§Modifier: & (filter)

Escapes special HTML characters and braces:

& → &amp;
< → &lt;
> → &gt;
" → &quot;
' → &#x27;
/ → &#x2F;
{ → &#123;
} → &#125;

By default all user variables are filtered, those starting with CONTEXT->. There is also a schema configuration to escape all variables filter_all:

{
    "config": {
        "filter_all": true
    },
    "inherit": {},
    "data": {}
}

Default is false.

§Modifier: ! (not)

Does not filter special HTML characters and braces, if combined with & the result is no filtering.

Avoid filtering a variable:

{:!;CONTEXT->GET->var:}

The contradictory combination with & results in no filtering:

{:&!;varname:}

§No flags

§Arrays

To access an array, use: “->”, no distinction between objects and arrays. Assuming:

{
    "data": {
        "arr": [
            "value"
        ],
        "obj": {
            "0": "value"
            "arr": [
                "value"
            ],
        }
    }
}

Then:

{:;arr->0:}
{:;obj->0:}
{:;obj->arr->0:}

§Dynamic evaluation

{:;array->{:;key:}:}

However, the following will produce an error:

{:;{:;varname:}:}

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

{:; {:allow; allowed-words-list >> {:;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.

§Undefined

It is not an error to use an undefined variable or an array, nor will it show any warning, in the case of an array it will show an empty string:

<div>{:;undefvar:}</div>
<div>{:;array:}</div>

Output:

<div></div>
<div></div>