westerveltco / django-simple-nav

A simple, flexible, and extensible navigation menu for Django
https://django-simple-nav.westervelt.dev
MIT License
10 stars 0 forks source link

Allow setting template content directly on `Nav`? #46

Open joshuadavidthomas opened 4 months ago

joshuadavidthomas commented 4 months ago

Curious about this, but as I create the demo with a bunch of examples, a thought occurred to me: should a nav's template be allowed to be set on the nav itself?

Example:

from django_simple_nav.nav import Nav
from django_simple_nav.nav import NavItem

class ExampleListNav(Nav):
    items = [
        NavItem(title="Tailwind CSS", url="/tailwind/"),
    ]
    template = """\
<ul>
  {% for item in items %}
    <li>
      <a href="{{ item.url }}"
         class="{% if item.active %}text-indigo-500 hover:text-indigo-300{% else %}hover:text-gray-400{% endif %}">
        {{ item.title }}
      </a>
    </li>
  {% endfor %}
</ul>"""
joshuadavidthomas commented 4 months ago

As mentioned in #55, instead of adding a new attribute directly, we could move to using a get_template method that could then be overridden to provide a template string directly.