Django needs a convenient way to generate HTML dynamically. The most common approach relies on templates. A template contains the static parts of the desired HTML output as well as some special syntax describing how dynamic content will be inserted.
In case of wagtail,For each page model in model.py, Wagtail assumes an HTML template file exists of the same name. The Front End developer may need to create these templates themselves by refering to model.py to infer template names from the models defined therein.
To find a suitable template, Wagtail converts CamelCase names to snake_case. So for a Blogpage, a template will be expected blog_page.html. The name of the template file can be overridden per model if necessary.
Template files are assumed to exist here:
name_of_project/
name_of_app/
templates/
name_of_app/
blog_page.html
models.py
Template tags & filters
Wagtail provides some tags && filters of its own here are list of some of the tags && filters:-
The Image tag inserts an XHTML-compatible img element into the page,setting its src, width, height and alt.
The syntax for the image tag is thus:
{% image [image] [resize-rule] %}
For example:-
{% load wagtailimages_tags %}
...
{% image page.photo width-400 %}
<!-- or a square thumbnail: -->
{% image page.photo fill-80x80 %}
Takes a Page object and returns a relative URL (/foo/bar/) if within the same Site as the current page
{% load wagtailcore_tags %}
{% for publication in page.related_publications.all %}
<li>
<a href="{% pageurl publication.detail_page fallback='coming_soon' %}">
{{ publication.title }}
</a>
</li>
{% endfor %}
2. slugurl
Takes any slug as defined in a page's "Promote" tab and returns the URL for the matching Page. If multiple pages exist with the same slug, the page chosen is undetermined.
{% load wagtailcore_tags %}
...
<a href="{% slugurl 'news' %}">News index</a>
Used to load anything from your static files directory. Use of this tag avoids rewriting all static paths if hosting arrangements change, as they might between development and live environments.
{% load static %}
...
<img src="{% static "name_of_app/myimage.jpg" %}" alt="My image"/>
Comments