1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
|
---
title: Variables
permalink: /docs/variables/
---
Jekyll traverses your site looking for files to process. Any files with [YAML
front matter](../frontmatter/) are subject to processing. For each of these
files, Jekyll makes a variety of data available via the [Liquid templating
system](https://github.com/Shopify/liquid/wiki). The
following is a reference of the available data.
## Global Variables
<div class="mobile-side-scroller">
<table>
<thead>
<tr>
<th>Variable</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><p><code>site</code></p></td>
<td><p>
Sitewide information + configuration settings from
<code>_config.yml</code>. See below for details.
</p></td>
</tr>
<tr>
<td><p><code>page</code></p></td>
<td><p>
Page specific information + the <a href="../frontmatter/">YAML front
matter</a>. Custom variables set via the YAML Front Matter will be
available here. See below for details.
</p></td>
</tr>
<tr>
<td><p><code>layout</code></p></td>
<td><p>
Layout specific information + the <a href="../frontmatter/">YAML front
matter</a>. Custom variables set via the YAML Front Matter in
layouts will be available here.
</p></td>
</tr>
<tr>
<td><p><code>content</code></p></td>
<td><p>
In layout files, the rendered content of the Post or Page being wrapped.
Not defined in Post or Page files.
</p></td>
</tr>
<tr>
<td><p><code>paginator</code></p></td>
<td><p>
When the <code>paginate</code> configuration option is set, this
variable becomes available for use. See <a
href="../pagination/">Pagination</a> for details.
</p></td>
</tr>
</tbody>
</table>
</div>
## Site Variables
<div class="mobile-side-scroller">
<table>
<thead>
<tr>
<th>Variable</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><p><code>site.time</code></p></td>
<td><p>
The current time (when you run the <code>jekyll</code> command).
</p></td>
</tr>
<tr>
<td><p><code>site.pages</code></p></td>
<td><p>
A list of all Pages.
</p></td>
</tr>
<tr>
<td><p><code>site.posts</code></p></td>
<td><p>
A reverse chronological list of all Posts.
</p></td>
</tr>
<tr>
<td><p><code>site.related_posts</code></p></td>
<td><p>
If the page being processed is a Post, this contains a list of up to ten
related Posts. By default, these are the ten most recent posts.
For high quality but slow to compute results, run the
<code>jekyll</code> command with the <code>--lsi</code> (<a href="https://en.wikipedia.org/wiki/Latent_semantic_analysis#Latent_semantic_indexing">latent semantic indexing</a>) option. Also note GitHub Pages does not support the <code>lsi</code> option when generating sites.
</p></td>
</tr>
<tr>
<td><p><code>site.static_files</code></p></td>
<td><p>
A list of all <a href="/docs/static-files/">static files</a> (i.e.
files not processed by Jekyll's converters or the Liquid renderer).
Each file has three properties: <code>path</code>,
<code>modified_time</code> and <code>extname</code>.
</p></td>
</tr>
<tr>
<td><p><code>site.html_pages</code></p></td>
<td><p>
A subset of `site.pages` listing those which end in `.html`.
</p></td>
</tr>
<tr>
<td><p><code>site.html_files</code></p></td>
<td><p>
A subset of `site.static_files` listing those which end in `.html`.
</p></td>
</tr>
<tr>
<td><p><code>site.collections</code></p></td>
<td><p>
A list of all the collections.
</p></td>
</tr>
<tr>
<td><p><code>site.data</code></p></td>
<td><p>
A list containing the data loaded from the YAML files located in the <code>_data</code> directory.
</p></td>
</tr>
<tr>
<td><p><code>site.documents</code></p></td>
<td><p>
A list of all the documents in every collection.
</p></td>
</tr>
<tr>
<td><p><code>site.categories.CATEGORY</code></p></td>
<td><p>
The list of all Posts in category <code>CATEGORY</code>.
</p></td>
</tr>
<tr>
<td><p><code>site.tags.TAG</code></p></td>
<td><p>
The list of all Posts with tag <code>TAG</code>.
</p></td>
</tr>
<tr>
<td><p><code>site.url</code></p></td>
<td><p>
Contains the url of your site as it is configured in the <code>_config.yml</code>.
For example, if you have <code>url: http://mysite.com</code>
in your configuration file, then it will be accessible in Liquid as
<code>site.url</code>. For the development environment there is
<a href="/news/#3-siteurl-is-set-by-the-development-server">an exception</a>,
if you are running <code>jekyll serve</code> in a development environment
<code>site.url</code> will be set to the value of <code>host</code>,
<code>port</code>, and SSL-related options. This defaults to
<code>url: http://localhost:4000</code>.
</p></td>
</tr>
<tr>
<td><p><code>site.[CONFIGURATION_DATA]</code></p></td>
<td><p>
All the variables set via the command line and your
<code>_config.yml</code> are available through the <code>site</code>
variable. For example, if you have <code>foo: bar</code>
in your configuration file, then it will be accessible in Liquid as <code>site.foo</code>.
Jekyll does not parse changes to <code>_config.yml</code> in
<code>watch</code> mode, you must restart Jekyll to see changes to variables.
</p></td>
</tr>
</tbody>
</table>
</div>
## Page Variables
<div class="mobile-side-scroller">
<table>
<thead>
<tr>
<th>Variable</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><p><code>page.content</code></p></td>
<td><p>
The content of the Page, rendered or un-rendered depending upon
what Liquid is being processed and what <code>page</code> is.
</p></td>
</tr>
<tr>
<td><p><code>page.title</code></p></td>
<td><p>
The title of the Page.
</p></td>
</tr>
<tr>
<td><p><code>page.excerpt</code></p></td>
<td><p>
The un-rendered excerpt of a document.
</p></td>
</tr>
<tr>
<td><p><code>page.url</code></p></td>
<td><p>
The URL of the Post without the domain, but
with a leading slash, e.g.
<code>/2008/12/14/my-post.html</code>
</p></td>
</tr>
<tr>
<td><p><code>page.date</code></p></td>
<td><p>
The Date assigned to the Post. This can be overridden in a Post’s front
matter by specifying a new date/time in the format
<code>YYYY-MM-DD HH:MM:SS</code> (assuming UTC), or
<code>YYYY-MM-DD HH:MM:SS +/-TTTT</code> (to specify a time zone using
an offset from UTC. e.g. <code>2008-12-14 10:30:00 +0900</code>).
</p></td>
</tr>
<tr>
<td><p><code>page.id</code></p></td>
<td><p>
An identifier unique to a document in a Collection or a Post (useful in RSS feeds). e.g.
<code>/2008/12/14/my-post</code>
<code>/my-collection/my-document</code>
</p></td>
</tr>
<tr>
<td><p><code>page.categories</code></p></td>
<td><p>
The list of categories to which this post belongs. Categories are
derived from the directory structure above the <code>_posts</code>
directory. For example, a post at
<code>/work/code/_posts/2008-12-24-closures.md</code> would have this
field set to <code>['work', 'code']</code>. These can also be specified
in the <a href="../frontmatter/">YAML Front Matter</a>.
</p></td>
</tr>
<tr>
<td><p><code>page.tags</code></p></td>
<td><p>
The list of tags to which this post belongs. These can be specified in
the <a href="../frontmatter/">YAML Front Matter</a>.
</p></td>
</tr>
<tr>
<td><p><code>page.path</code></p></td>
<td><p>
The path to the raw post or page. Example usage: Linking back to the
page or post’s source on GitHub. This can be overridden in the
<a href="../frontmatter/">YAML Front Matter</a>.
</p></td>
</tr>
<tr>
<td><p><code>page.next</code></p></td>
<td><p>
The next post relative to the position of the current post in
<code>site.posts</code>. Returns <code>nil</code> for the last entry.
</p></td>
</tr>
<tr>
<td><p><code>page.previous</code></p></td>
<td><p>
The previous post relative to the position of the current post in
<code>site.posts</code>. Returns <code>nil</code> for the first entry.
</p></td>
</tr>
</tbody>
</table>
</div>
<div class="note">
<h5>ProTip™: Use Custom Front Matter</h5>
<p>
Any custom front matter that you specify will be available under
<code>page</code>. For example, if you specify <code>custom_css: true</code>
in a page’s front matter, that value will be available as
<code>page.custom_css</code>.
</p>
<p>
If you specify front matter in a layout, access that via <code>layout</code>.
For example, if you specify <code>class: full_page</code>
in a layout’s front matter, that value will be available as
<code>layout.class</code> in the layout and its parents.
</p>
</div>
## Paginator
<div class="mobile-side-scroller">
<table>
<thead>
<tr>
<th>Variable</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><p><code>paginator.per_page</code></p></td>
<td><p>Number of Posts per page.</p></td>
</tr>
<tr>
<td><p><code>paginator.posts</code></p></td>
<td><p>Posts available for that page.</p></td>
</tr>
<tr>
<td><p><code>paginator.total_posts</code></p></td>
<td><p>Total number of Posts.</p></td>
</tr>
<tr>
<td><p><code>paginator.total_pages</code></p></td>
<td><p>Total number of pages.</p></td>
</tr>
<tr>
<td><p><code>paginator.page</code></p></td>
<td><p>The number of the current page.</p></td>
</tr>
<tr>
<td><p><code>paginator.previous_page</code></p></td>
<td><p>The number of the previous page.</p></td>
</tr>
<tr>
<td><p><code>paginator.previous_page_path</code></p></td>
<td><p>The path to the previous page.</p></td>
</tr>
<tr>
<td><p><code>paginator.next_page</code></p></td>
<td><p>The number of the next page.</p></td>
</tr>
<tr>
<td><p><code>paginator.next_page_path</code></p></td>
<td><p>The path to the next page.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="note info">
<h5>Paginator variable availability</h5>
<p>
These are only available in index files, however they can be located in a
subdirectory, such as <code>/blog/index.html</code>.
</p>
</div>
|