1
votes

I have one simple custom template tag:

@register.simple_tag
def show_language_choice_dropdown_menu():
    return SHOW_LANGUAGE_CHOICE_DROPDOWN_MENU

which gets boolean value from settings. If I simply put it in text there is no problems, right value appears, but if i try to check:

{% if show_language_choice_dropdown_menu %}

it doesn't work - every time is False. What's wrong?

1
have you included it as {% load awesome_tags_file %} in your html ? - pptt

1 Answers

2
votes

I wonder if you could do this way. The if statement looks for variable show_language_choice_dropdown_menu and probably there is no such variable. Try using assignment tag instead:

@register.assignment_tag
def show_language_choice_dropdown_menu_tag():
  return SHOW_LANGUAGE_CHOICE_DROPDOWN_MENU

and then use it as following:

{% show_language_choice_dropdown_menu_tag as show_language_choice_dropdown_menu %}
{% if show_language_choice_dropdown_menu %}

For more information please refer to https://docs.djangoproject.com/en/1.8/howto/custom-template-tags/#assignment-tags