Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3318056
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:39:38+00:00 2026-05-17T22:39:38+00:00

When there is a dictionary: menu = {‘title’: ‘Link1’, ‘children’: {‘title’: ‘Child of Link1’,

  • 0

When there is a dictionary:

menu = {'title': 'Link1',
        'children': {'title': 'Child of Link1',
                     'children': #etc..}
        }

How would one iterate over it so that the output becomes:

<ul>
    <li>Link1
    <ul>
        <li>Child of Link 1
            <ul>
               <li>Grandchild of Link 1
               <ul>etc..</ul>
               </li>
             </ul>
         </li>
     </ul>
     </li>
</ul>

Currently I use this, but it obviously only goes to a depth of one.

    <ul id="mainnavigation">     
    {% for k,v in admin.items %} #ContextProcessor, because this menu needs to know the current path.
            <li class="expandable"><a href="{{ v.path }}">{{ v.title }}</a>
                {% if v.children != None %}
                    <ul>
                    {% for id,child in v.children.items %}
                            <li class="expandable"><a href="{{ child.path }}">{{ child.title }}</a></li>
                    {% endfor %}
                    </ul>
                {% endif %}
            </li>
    {% endfor %}
</ul>

One way would be to manually repeat the loop for each level, however such a solution is ugly and I am hoping there is a more DRY one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:39:38+00:00Added an answer on May 17, 2026 at 10:39 pm

    You’ll have to make custom template tag for this. I would choose inclusion tag.

    {% for k,v in var %}
    {% my_tag v.children %}
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title says, is there a dictionary similar to Objective-C's NSDictionary for C++?
There are several places on the internet that talk about having multy key dictionary
I currently have a menu with subitems that is being stored in this dictionary
Is there a good way of marshalling a Dictionary<string, string> over COM interop? Ideas
Is there any JavaScript library that makes a dictionary out of the query string,
Is there any dictionary out there containing adult words (black/grey) to identify websites? Would
is there a dictionary i can download for java? i want to have a
Hi in my code there is a dictionary of dictionary. nrec={'bridge': 'xapi1', 'current_operations': {},
Is there a simple description of how the dictionary file in Proguard should be
is there any way to store duplicate keys in a dictionary? I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.