Pooja
Pooja

Reputation: 796

django inclusion tag not working

I am using inclusion tag to show menu in my site. But is not working as expected. It is not even throwing any error.

vertical_meny.py

from django import template

register = template.Library()

@register.inclusion_tag('vertical-menu.html')
def give_menu_items():
    abc =[
            {'name':'as', 'link':'/somelink'},
            {'name':'lsl', 'link':'somelink2'},

    ]

    pqr =[
            {'name':'sd', 'link':'/somelink3'},
            {'name':'sdd', 'link':'somelink2'},

     ]

    my_tabs = [
            {'name':'Main', 'link':'/main', 'subtabs': abc},
            {'name':'Advanced', 'link':'/advanced', 'subtabs': pqr},

      ]

    return { 'my_tabs' : my_tabs, }

vertical-menu.html

<div class="col-md-3 md-margin-bottom-20">
<div class="panel-group menu-v1">

    {% for tab in my_tabs %}
       <h1>Hello</h1>
       <li>{{ tab }}</li>
    {%endfor%}
    </div>
</div>

base.html

{% load vertical_menu%}

{% include 'vertical-menu.html' %}

django is not going inside the for loop of vertical-menu.html and is not rendering any html within it. It seems my_tabs does not contain anything. I don't know where I am going wrong. Please help.

Upvotes: 0

Views: 719

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599470

That's not how you use an inclusion tag. You don't include the template directly, you just call the tag.

{% give_menu_items %}

Upvotes: 2

Related Questions