Skip to content

Consider using a python function for our sidebar templating #109

@choldgraf

Description

@choldgraf

I find the sidebar templating logic to be a bit confusing to wrap my head around. I wonder if it could be made a little bit more modular if we generated that HTML with a Python function. E.g., I feel like we must be able to generate that structure with a recursive function, similar to how we parse the nav items on the page.

Maybe this would be easier than having a bunch of if/then statements in the Jinja itself? I tried making a little demo function, and if we pass it nav like so:

{{ my_func(nav) }}

then nav has this structure:

[{'active': False,
  'children': [],
  'title': 'User Guide',
  'url': '../user_guide/index.html'},
 {'active': False,
  'children': [],
  'title': 'Contributing',
  'url': '../contributing.html'},
 {'active': True,
  'children': [{'active': False,
    'children': [],
    'title': 'Structural Elements',
    'url': 'structure.html'},
   {'active': False,
    'children': [],
    'title': 'Paragraph Level Markup',
    'url': 'demo.html'},
... and so on

So it might be easy to loop through that and recursively generate the right HTML. Do you think this is worth a shot? Or am I over-thinking this?

(one reason I'm interested in this is to make it easier to switch back-and-forth between "sidebar + topbar" and "only sidebar" layouts)

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs: discussionNeeds discussion before an implementation can be made

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions