picea/docs/02-control-structure-use.md

808 B

Control structure - Use

While working with inside a template, it might be needed that you reference some other namespaces.

The use clause works exaclty like PHP's vanilla top of the page use.

[PICEA] So, using this code:

{% use AnyVendor\My\Super\Randomizer %}

{# One chance out of ten to end this loop %}
{% while Randomizer::run(1, 10) === 10 %}
    {% if Randomizer::run(1, 100) < 50 %} 
        <span>Lower than 50 !</span>
    {% else %}
        <strong>Greater than 50 !</strong>
    {% endif %}
{% endwhile %}

<h4>DONE !</h4>

[HTML] Could render as such output:

<span>Lower than 50 !</span>
<span>Greater than 50 !</span>
<span>Lower than 50 !</span>
<span>Greater than 50 !</span>
<span>Lower than 50 !</span>
<span>Lower than 50 !</span>
<h4>DONE !</h4>