Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conditional boolean attributes #111

Open
iceripple opened this issue Nov 27, 2012 · 5 comments
Open

conditional boolean attributes #111

iceripple opened this issue Nov 27, 2012 · 5 comments

Comments

@iceripple
Copy link

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

@D3X
Copy link

D3X commented Dec 27, 2012

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:

  1. install pyparsing if you want to use this fork
  2. tell me what's broken :)

@peterbehr
Copy link

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.)

@skatenerd
Copy link

👍

1 similar comment
@jlward
Copy link

jlward commented Mar 23, 2017

+1

@D3X
Copy link

D3X commented Mar 23, 2017

@peterbehr @skatenerd @jlward Better late than never, I guess: #172
Now you have to push @jessemiller to merge it upstream :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants