Templating Example

Calling a fragment in the template

You will need to call the fragment by editing the template for the page where you want the fragment to render. For example, if you want the fragment to appear on all section pages, you would need to call the fragment in the /templates/site-name/news/section_default.html template. Using the Javascript_Example fragment from the Using The Fragments Application documentation, we can call the fragment in the template like so:

<div id="javascript_example">
    {% fragment Javascript_Example as ap_widget %}
        <h6>Javascript Example</h6>
        {{ ap_widget.content|safe }}
Click to copy

Putting it altogether, we have a fragment object in the admin, populated with javascript, and loaded in the template. The result would look something like the following:


Once called in the template, fragments provide a powerful and convient way to manage blocks of HTML and Javascript entirely from the admin.


Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.