Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: nested custom template tags

I have written 2 custom template tags in Django. The goal is to use one custom tag inside of another. Is it permitted? The template for custom "outer" tag looks like this:

<ul>
    {% for type in types %}
         {% custom_internal_tag param1 %}
    {% endfor %}
</ul>

Which after rendering results in

Invalid block tag: 'custom_internal_tag', expected 'empty' or 'endfor'

Are nested custom tags allowed? What would be the cause of such an error?

like image 423
AlexA Avatar asked Dec 20 '25 06:12

AlexA


1 Answers

They are definitely allowed, but that error can come up because your custom tag is not properly defined, located or loaded.

Make sure all your custom tags are located in your app/templatetags directory and are loaded properly, usually using the @register decorator.

Reference: https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#registering-custom-filters

like image 190
Yuval Adam Avatar answered Dec 22 '25 19:12

Yuval Adam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!