conditional boolean attributes
You often need to set boolean attributes (checked, selected,disabled) conditionally in a template
in Haml you can do something like:
%input{:selected => false}
which will evaluate to:
<input>
of course, Hamlpy cannot do this as it doesn't have access to runtime variables. a line like:
%button{'disabled' : ={button_disabled}}
wlll always result in a disabled button, whatever the value of button_disabled
Any better solutions than the ones I have come up with?
-if next_disabled
%button{'disabled':'disabled'} Next...
-else
%button Next...
very un-dry, especially if the element has a lot more attributes Or just insert raw django template stuff:
<button {% if next_disabled %}disabled="disabled"{% endif %}>Next…</button>
being somewhat counter-intuitive when you have elected to use Haml
Take a look at my fork: https://github.com/D3X/HamlPy I added support for conditional attributes. It's not production-ready yet, i hope to clean it up soon. Don't forget to:
- install pyparsing if you want to use this fork
- tell me what's broken :)
I would love to see this supported, @D3X any chance the change you made to your fork could easily be submitted as a pull request to the parent repo? (I could use your fork personally, but not on any of the collaborative projects I'm working on that could use this feature.)
:+1:
+1
@peterbehr @skatenerd @jlward Better late than never, I guess: https://github.com/jessemiller/HamlPy/pull/172 Now you have to push @jessemiller to merge it upstream :)