Maybe you can solve this using a templatetag?

On Wed, 13 Feb 2019, 16:47 Mikkel Kromann <mik...@aabenhuskromann.dk wrote:

> Hi.
>
> I have a collection of apps where I find repeating myself when rendering
> tables in the templates.
> In the stylised example below I have three types of tables, foo, bar and
> baz.
> Each app is supposed to render various combinations of tables from its own
> models, but also from other models' tables.
> (yes, it is a hideously complex structure - and believe me, I've tried to
> simplify it a lot - even with some success)
>
> Can I - in a page which extends a base, include various "template
> snippets", so that I can reuse the template snippets across several apps?
>
> base.html:
> <html>
> ...
> </html>
>
> my_page1.html:
> {% extends "base.html" %}
>
> {% block foo %}
> {% include foo.html %}
> {% endblock % }
>
> {% block bar %}
> {% include bar.html %}
> {% endblock % }
>
> {% block baz %}
> {% include baz.html %}
> {% endblock % }
>
> foo.html:
> {% if foo_context %}
> <!-- do stuff with foo -->
> {% endif %}
>
> bar.html:
> {% if bar_context %}
> <!-- do stuff with bar -->
> {% endif %}
>
> baz.html:
> {% if baz_context %}
> <!-- do stuff with baz -->
> {% endif %}
>
> As I understand, the snippets are evaluated without the context of
> my_page1.html, right (e.g. foo_context).
> The docs (
> https://docs.djangoproject.com/en/2.1/ref/templates/builtins/#include)
> seem to suggest that I could work around the context problem by writing:
>
> {% include foo.html with foo_context=foo_context %}
>
>
> Is that correctly understood in this case?
>
>
> thanks, Mikkel
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8b0eca46-1d00-4bdd-8aba-d8d3a2043a1b%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8b0eca46-1d00-4bdd-8aba-d8d3a2043a1b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFWa6tK_J%3Dot4_rZx8n%3Dfv5R%3DBazDHCUrk1NQCxtGw5PfZVMEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to