posthtml / posthtml-expressions

Use variables, JS-like expressions, and even markup-powered logic in your HTML.
Other
123 stars 20 forks source link

Set attributes via locals #137

Open thewebartisan7 opened 1 year ago

thewebartisan7 commented 1 year ago

It seem that it's not possible to set attributes via locals, but only values.

So it's not possible to set dynamically the "selected" or "disabled" attribute to a select or input tag.

It's that correct?

I tried several things but seem not working.

Would be possible to set something like:

<select>
<option :selected="{{ selected }}">option 1</option>
<option>option 2</option>
</select>

Notice the ":" before attribute. When this and when {{ selected }} value is undefined, NULL and/or false, then :selected attribute get removed from tag.

Maybe would better a custom plugin that loop over tag with such attributes and remove attribute when condition match?

What do you think?

thewebartisan7 commented 1 year ago

I made a small plugin for handle this, it's pretty easy. Will publish it soon.