Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Volt syntax {%- & {{-

Hi there,

In this Github repository:

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.

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 %}

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>

but this:

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

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>


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.



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

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