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

Django if-else tags common inner content #159

Open
l0kix2 opened this issue Apr 5, 2014 · 1 comment
Open

Django if-else tags common inner content #159

l0kix2 opened this issue Apr 5, 2014 · 1 comment

Comments

@l0kix2
Copy link

l0kix2 commented Apr 5, 2014

It's hard to describe my problem in summary, so i do it in example

I want to get html with div with img inside. Sometimes I want to assign one class to div tag, sometimes another. So i end up django-hamlpy template like this:

- if condition
  .active
    %img{'src': '={ image_obj.url }'}
- else
   .inactive
    %img{'src': '={ image_obj.url }'}

But I don't like %img{'src': '={ image_obj.url }'} copypaste in both blocks. It wasn't a problem with simple django tags, because there is endif tag and indents means nothing, but now i can't see how to do it in my new template scheme. How can i write django-haml markup without repeating tag content?

Maybe one just can't do something like that using indent-sensitive language and i should fallback to simple django tags, i still can use them as-is, right?

@davidtingsu
Copy link

Try using the yesno filter:

%div{ class: "{{ condition|yesno"active,inactive" }}" }
%img{'src': '={ image_obj.url }'}

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

2 participants