I am building a Django website and my side bar can have different elements for different users. So my main sidebar template has a div for every plugin to be included and the specific HTML for every one of these plugins is included in their own template file.
example:
<div id="plugins">
<div id="plugin1">
{% include 'plugin1.html' %}
</div>
<div id="plugin2">
{% include 'plugin2.html' %}
</div>
</div>
Now I want to build this list dynamically how could I do it? As the template is only parsed once so I could not send it a '{% include 'plugin1.html'}' string in the context
Any ideas?
A Django template is a text document or a Python string marked-up using the Django template language. Some constructs are recognized and interpreted by the template engine. The main ones are variables and tags. A template is rendered with a context.
{% include %} Processes a partial template. Any variables in the parent template will be available in the partial template. Variables set from the partial template using the set or assign tags will be available in the parent template.
As with every web framework, Django has a templating engine for creating dynamic HTML. The information that the user wants to access is created by this engine and presented through views.
Using Views and Django Template we can display data in the template. There are lots of Django Template Tags and Filter for displaying data dynamically. We can pass the Model data to view for rendering it in the template.
You can use a variable inside the include
tag:
{% include my_user_html %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With