arnaud-lb / MtHaml

Multi target HAML (HAML for PHP, Twig, <your language here>)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conditional attribute interpolation

unirgy opened this issue · comments

Sometimes I need to handle conditional minified attributes, such as hidden and it requires interpolation outside of attribute value, because this will still be make element hidden even if attribute value is empty:

%section(id="foo" hidden="#{$hidden ? 'hidden' : ''}")

So, I've tried this and it worked, which makes me happy:

%section(id="foo" #{$hidden ? 'hidden="hidden"' : ''})

But it works only if there's another attribute in front of it, as this doesn't work:

%section(#{$hidden ? 'hidden="hidden"' : ''})

This makes me think - am I using an undocumented feature, which might be lost at some point?

Thanks

HAML supports boolean attributes (and so does MtHaml) :

@section(hidden=$hidden)

Will render like this if $hidden is true:

html5: <section hidden>
xhtml: <section hidden="hidden">

Or like this if $hidden is false:

<section>

But it works only if there's another attribute in front of it, as this doesn't work:

%section(#{$hidden ? 'hidden="hidden"' : ''})

Are you using the lastest MtHaml version ?