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

Feature request: Add template filters for switch_is_active, flag_is_active, sample_is_active #510

Open
MatthewEthanTam opened this issue Nov 2, 2024 · 5 comments

Comments

@MatthewEthanTam
Copy link

MatthewEthanTam commented Nov 2, 2024

In my usage of Django-waffle, I found that I cannot use the switch template tag within an if statement's condition in Django templates as some blocks of code require both the switch to be active and another context variable to be set.

Please find an example of this case below:

{% switch 'switch'%}
  {% if context_variable %}
    modified message
  {% else %}
    default message
  {% endif %}
{% else %}
  default
{%endswitch%}

Suggestion: I suggest we make template filters for switch_is_active, flag_is_active, and sample_is_active, this will allow the reduction of redundant code in this scenario.

an example of this suggestion is below:

{% if 'switch'|switch_is_active and context_variable%}
  modified message
{% else %}
  default message
{% endif %}

If this is a good suggestion, I can make a PR for it.

@MatthewEthanTam MatthewEthanTam changed the title Feature request: Add template filters for switch, flag, sample Feature request: Add template filters for switch_is_active, flag_is_active, sample_is_active Nov 2, 2024
@steynvl
Copy link

steynvl commented Nov 4, 2024

Would find use for this in my projects using django-waffle

@whoiskrtk2
Copy link

Hi! I'm just starting with open source and I'd love to give this a try.

@whoiskrtk2
Copy link

@clintonb @dancergraham bump

@dancergraham
Copy link
Contributor

Hello, I don't really use templates so I don't have an opinion on this and wouldn't be much help getting started on a PR - I would start by putting a question on the django forum to see whether anyone has a good shorthand for this using existing template features such as https://docs.djangoproject.com/en/5.1/ref/templates/builtins/#with with statements (random idea - don't know whether it is relevant.

@MatthewEthanTam
Copy link
Author

Thank you for the suggestion @dancergraham, @whoiskrtk2 I have already forked the repo and have a PR feature branch ready, I am happy to walk the PR through with you 👍🏻

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

4 participants