Templates
Blades uses mustache templates with the
57 | Ramhorns engine. While their syntax is simple
58 | (and can be learned in a few minutes), they are surprisingly expressive.
59 | Templates are loaded from the templates
subdirectory, or secondarily from the themes/$theme/templates
60 | directory if a theme is specified in the config.
61 | Here is the list of variables available to use in templates. Apart from these,
62 | any other variable of any type specified on the page
63 | or in the site config can also be used.
64 | These variables are common for all pages:
65 |
66 | // The data of the whole site
67 | site: Site
68 | // Main page in the site
69 | index: Page
70 | // A dictionary of all the taxonomies used in the site
71 | classification: Map<string, Taxonomy>
72 |
73 | Page
74 | When rendering a page, these variables are available:
75 |
76 | // Title of the page
77 | title: string
78 | // Date when the page was created
79 | date: Option<DateTime>
80 | // Image representing the page
81 | image: string
82 | // A brief summary of the page
83 | summary: string
84 | // The main content of the page
85 | content: string
86 | // The full link of the page, with the site URL included
87 | permalink: string
88 | // The path of the page, beginning with /
, without the last segment
89 | // When rendered as section ({{#path}}), it acts as a list of Ancestors
90 | path: string
91 | // The trailing segment of this page’s URL
92 | // Without the .html extension
93 | // For sections, it’s the folder name rather than index
94 | slug: string
95 | // A list of alternative paths where this page is rendered to, if any
96 | alternative_paths: List
97 | // A list of classifications for each of the provided taxonomies
98 | taxonomies: Map<string, List<string>>
99 | // A list of pictures provided by this page
100 | pictures: List<Picture>
101 | // Is this page a section?
102 | is_section: bool
103 | // Is the page hidden from the list of its parent’s subpages and subsections?
104 | hidden: bool
105 | // A priority of this page for SEO, in the range of 0-1
106 | priority: float
107 | // The page one level up in the hierarchy (for the index page it’s itself)
108 | parent: Page
109 | // The previous page on this level, if any
110 | previous: Option<Page>
111 | // The next page in this level, if any
112 | next: Option<Page>
113 | // A list of all the subpages (empty if not section)
114 | pages: List<Page>
115 | // A list of all the subsections (empty if not section)
116 | subsections: List<Page>
117 | // Available when the subpages are paginated
118 | pagination: Option<Pagination>
119 | // Marks whether this page is the active one
120 | // Can be used to highlight the current page in a list of pages
121 | active: bool
122 |
123 |
124 | When the pagination is available, you can use these variables in the pagination section
125 | ({{#pagination}} ... {{/pagination}}
):
126 |
127 | // Number of the current page in the paginated pages
128 | current: integer
129 | // Number of the previous page in the paginated pages
130 | // This is also its slug
131 | previous: Option<integer>
132 | // Number of the next page in the paginated pages
133 | // This is also its slug
134 | next: Option<integer>
135 | // Number of the paginated pages
136 | length: integer
137 |
138 | Ancestors
139 | When the page path is used as a section ({{#path}} ... {{/path}}
), it is interpreted
140 | as a list of ancestors. This makes making breadcrumbs possible.
141 | For the path segments, the following are available:
142 |
143 | // Name of the current path segment
144 | name: string
145 | // The full path up to this segment
146 | full: string
147 |
148 | DateTime
149 | When the date is available, you can use these variables in the datetime section
150 | ({{#date}} ... {{/date}}
), roughly corresponding to strftime:
151 |
152 | // Year
153 | y: integer
154 | // Month
155 | m: integer
156 | // Day, 0-padded
157 | d: integer
158 | // Day, space-padded
159 | e: integer
160 | // Hour
161 | H: integer
162 | // Minute
163 | M: integer
164 | // Second
165 | S: integer
166 | // First 3 letters of the English month name
167 | b: string
168 | // First 3 letters of the English weekday name
169 | a: string
170 |
171 | Picture
172 | When pictures are available, you can use these variables in the pictures section
173 | ({{#pictures}} ... {{/pictures}}
for a list of them):
174 |
175 | # Id string of the picture, used for the generated URL in the gallery page
176 | pid: string
177 | # An associated caption of the picture
178 | caption: string
179 | # An alternative text displayed when the image can’t be loaded of for accessibility
180 | alt: string
181 | # File name of the image
182 | file: string
183 | # Date and time of when the image was taken
184 | taken: Option<DateTime>
185 | // The full link of the picture, with the site URL included
186 | permalink: string
187 |
188 | Gallery
189 | When a page contains come picture, the gallery is created. The page of each photo in the gallery
190 | gets the following variables:
191 |
192 | // The current picture
193 | current: Picture
194 | // The previous picture in the list (the last one for the first one)
195 | previous: Picture
196 | // The next picture in the list (the first one for the last one)
197 | next: Picture
198 | // The parent page, from which this gallery is generated
199 | parent: Page
200 |
201 | Taxonomy
202 | Each taxonomy that is rendered gets the following variables:
203 |
204 | // Full name of the taxonomy
205 | title: string
206 | // A short name of the taxonomy, used in the URL
207 | slug: string
208 | // A brief description of the taxonomy
209 | description: string
210 | // A list of keys used in this taxonomy and their corresponding pages
211 | keys: List<KeyPages>
212 |
213 | Key pages
214 | When keys in the taxonomy are available, you can use these variables in the keys section
215 | ({{#keys}} ... {{/keys}}
for a list of them):
216 |
217 | // Name of this key (also used in the URL of the key page)
218 | key: str
219 | // All the pages with this key in this taxonomy
220 | pages: List<Page>
221 |
222 | Taxonomy key
223 | When rendering a page of a single taxonomy key, these variables are available:
224 |
225 | // Name of this key (also used in the URL)
226 | title: string
227 | // The parent taxonomy where this key belongs to
228 | taxonomy: Taxonomy
229 | // The pages using this key
230 | pages: List<Page>
231 | // Optional pagination, if enabled for this taxonomy
232 | pagination: Option<Pagination>
233 |
234 | Site
235 | The data of the whole site, available for every page in the site section
236 | ({{#site}} ... {{/site}}
):
237 |
238 | // The main title of the site
239 | title: string
240 | // The main URL of the site
241 | url: string
242 | description: string
243 | keywords: string
244 | // A representative image of the site
245 | image: string
246 | // Info about the author of the site
247 | author: Author
248 | // Path of the site where the assets are moved to
249 | assets: string
250 | // Is sitemap rendered?
251 | sitemap: bool
252 | // Is atom feed rendered?
253 | atom: bool
254 | // Is RSS feed rendered?
255 | rss: bool
256 | // Are taxonomies not explicitly defined in the config, but used in some page rendered?
257 | implicit_taxonomies: bool
258 | // Are pages without date provided assigned the date of file creation?
259 | dates_of_creation: bool
260 |
261 | Author
262 | Info about the site author, available as a subsection of site
263 | ({{#site}}{{#author}} ... {{/author}}{{/site}}
):
264 |
265 | name: string
266 | uri: string
267 | email: string
268 | avatar: string
269 |
270 | For an actual example of templates in Blades, you can take a look at the
271 | code of this site, or of various
272 | themes.
273 |