Skip to content

Templating

Thorsten Marx ㋡ edited this page Nov 20, 2023 · 6 revisions

For information about configuration of template engien to be used see the per host config

Navigation

Navigation is realy simple.

<ul th:with="nodes=${navigation.list('/')}">
    <li th:each="node : ${nodes}" th:if="${node.path} != '/'">
        <a th:attr="aria-current=${node.current ? 'page' : ''}"
            th:classappend="${node.current}? 'active'"
            th:href="${node.path}"
			th:text="${node.name}"></a>
	</li>
</ul>

List of pages

Whenever you want to print out a list of pages, the nodeListFunction is a tiny little helper.
Keep in mind, that the nodelist function does not return the hole rendered HTML content but just an excerpt of 200 characters.

<!-- example for a blog overview page  -->
<div
	th:with='page = ${nodeList.from("/blog/*").sort("published").reverse(true).page(1).size(5).list()}'>
	<th:block th:each="entry : ${page.items}">
		<h2 th:text="${entry.name}"></h2>
		<p th:text="${entry.content}"></p>
		<u th:text="${#dates.format(entry.meta['published'], 'dd-MM-yyyy HH:mm')}"></u>
		<a th:href="${entry.path}">goto</a>
	</th:block>
</div>

UseCase Blog

Assume, your project has the following content structure for the blog, with the defaults page = 1 and pageSize = 5

blog/
---2023-09/
------entry1.md
------entry2.md
---2023-10/
------entry1.md

This nodeList call will return all content nodes in all subfolders of the folder blog/

${nodeList.from("/blog/*").list()}

Query nodes

The query-function allows you to query nodes by meta attributes.

<th:block th:each="featured : ${query.create().where('featured', true).get(0, 1)}">
    <div class="featured">
        <h3 th:text="${featured.name}"></h3>
	<a th:href="${featured.path}">goto</a>
    </div>
</th:block>
Clone this wiki locally