Friday 15 August 2014

templates - Extending breadcrumbs with block.super in django using DRY priniples -



templates - Extending breadcrumbs with block.super in django using DRY priniples -

i having problem implementing django_breadcrumbs in dry fashion using block.super.

i have template "editions" user can reach in 1 of 2 ways: either home, in case user sees editions, or template "surveys", in case user sees editions survey. breadcrumbs editions template , work fine:

{% extends 'base.html' %} {% load django_bootstrap_breadcrumbs %} {% block breadcrumbs %} {{ block.super }} {% if slug %} {% breadcrumb "surveys" "surveys:index" %} {% breadcrumb "editions" "editions:index" slug=slug %} {% else %} {% breadcrumb "editions" "editions:index" %} {% endif %} {% endblock %}

disappoinment ensues pages hang off editions template. had hoped extending page , using block.super, inherit proper breadcrumbs depending on edition came from. ever editions breadcrumb when hoped surveys / editions breadcrumbs. here template "create" hangs off "edition":

{% extends 'editions/index.html' %} {% load bootstrap3 %} {% load django_bootstrap_breadcrumbs %} {% block breadcrumbs %} {{ block.super }} {% breadcrumb "create" "editions:create" %} {% endblock %}

i set if: else: in template, rather inherit if: else: previous template. don't understand? need pass slug super:block or something? how without repeating same if: else: in kid template? indeed, how @ new if: else:?

thanks

john

my best guess render sec template without passing slug variable. inheritance correct, parent (or super) template uses slug variable, renders depends on variable's contents. therefore, if no variable called slug passed, else-part of if statement.

so, solution seems quite simple: add together slug variable context parameter when triggering template render.

django templates

No comments:

Post a Comment