You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The **Nunjucks** template engine offers a highly versatile option for transforming JSON/XML responses into HTML. Nunjucks provides additional functionality: if the specified template is not found in the document (e.g., via a `<script>` tag), it will send an AJAX request to fetch the template from the server dynamically. How Nunjucks Resolves Templates:
195
+
196
+
1.**Client-Side Template Resolution**: If a [`<script>` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) or [`<template>` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template) with the specified template ID (e.g., `dynamic-template`) exists, Nunjucks will render the data using this template.
197
+
2.**Server-Side Template Resolution**: If the template is not found in the DOM, Nunjucks will automatically make an HTTP request to fetch the template file from the server using the name as the file path. For example, specifying `nunjucks-template="user-template.html"` will prompt Nunjucks to request `/user-template.html` from the server. This capability is particularly useful for creating dynamic, server-generated templates that aren't hardcoded into the page.
198
+
199
+
200
+
```html
201
+
<!DOCTYPE html>
202
+
<htmllang="en">
203
+
<head>
204
+
<metacharset="utf-8">
205
+
<metaname="viewport"content="width=device-width">
206
+
<title>Nunjucks Example</title>
207
+
<!-- Include HTMX, the extension, and Nunjucks -->
0 commit comments