0

Let's say I have a partial template post.html:

<h2>{{ post.title }}</h2>
<p>{{ post.content }}</p>

<script src='myscript.js'></script>

And a regular template posts.html:

<h1>Posts</h1>
{% for post in posts %}
    {% include "partials/post.html" %}
{% endfor %}

Should I reference the script from every template I want to use the partial from instead of from the partial itself? Or is there a better way to prevent the script tag from being duplicated?

lennertcl
  • 93
  • 6
  • If I refer to this post I assume I should put the script inside the regular template? – lennertcl Sep 27 '21 at 08:26
  • 1
    Typically, if you use template inheritance (and have a `base.html` or `layout.html` as most tutorials on tempates mention) then script includes should go in here, ensuring they appear on every template. – v25 Sep 27 '21 at 08:45

1 Answers1

0

Script tags should go in regular templates that use the partial templates

lennertcl
  • 93
  • 6