We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Volt syntax {%- & {{-

Hi there,

In this Github repository:

https://github.com/phalcon/forum/blob/cc99c8b01d6defa63a69a729c4e58e8bb5e53e05/app/views/discussions/reloadCategories.volt

I can see that {%- and {{- are used but this doesn't appear to be a Volt 'macro'.

Can anyone help with an explanation as to why the - (minus) character is being placed after {% and {{ ? I checked the documents but couldn't find a similar reference in the Volt section that didn't specify a macro. As I said, the code in the link above doesn't look like a macro.

Many thanks.



940
Accepted
answer
edited May '14

Hi @G Wynne,

the only difference about {%- and {% I know, is that {%- creates inline html. For example an unordered list:

<ul id="nav" class="menu">
    {% for menu in menus %}
        <li>{{ link_to(menu.url, menu.title|e) }}</li>
    {% endfor %}
</ul>

this would output:

<ul id="nav" class="menu">
    <li><a href="/home">Home</a></li>
    <li><a href="/about">About</a></li>
    <li><a href="/news">News</a></li>
    <li><a href="/vita">Vita</a></li>
</ul>

but this:

<ul id="nav" class="menu">
    {%- for menu in menus -%}
        <li>{{- link_to(menu.url, menu.title|e) }}</li>
    {%- endfor -%}
</ul>

would output:

 <ul id="nav" class="menu"><li><a href="/home">Home</a></li><li><a href="/about">About</a></li><li><a href="/news">News</a></li><li><a href="/vita">Vita</a></li></ul>


38.8k

Hi there @screenas

Thanks for letting me know this! I guess the dash '-' makes sense. Now I look at it, it sort of says to me "inline" :)

I appreciate you taking the time to answer my question.

Regards

--G

Thanks @screenas - I had no idea about that. Definitely useful.

Thanks @screenas, I'm just looking for some document cover it.