Blot

Clarifying variable scope in templates?

I'm a bit confused about the scope of tag names from the Reference page:

For example, the reference lists blog.title and entry.title, but on the entries.html they don't seem to work for me. However the unqualified title does work.

Asked 4 years ago Edit
4 replies

Only the template view entry.html is supplied a single entry, corresponding to its permalink, whose title you can render like this:

<h1>{{entry.title}}</h1>

The template view entries.html is supplied a list of entries, paginated. You can render a list of their titles like so:

<ul>
  {{#entries}}
    <li>{{title}}</li>
  {{/entries}}
</ul>

At the moment, in contrast to what the docs claim, the blog properties are assigned to the top-level context, so {{title}} will refer to blog.title by default:

<p>This will show my blog's title:</p>
<h1>{{title}}</h1>
<p>This will show my most recent entry's title:</p>
<h1>{{#allEntries}}{{#first}}{{title}}{{/first}}{{/allEntries}}</h1>

I plan to eventually nest all the blog properties under {{blog}} but the template rendering engine hasn't caught up to the documentation yet. If in doubt, please follow the conventions followed by the templates. Please let me know if you have any questions about this or anything else.

4 years ago Edit

I just spent a half hour trying to get my site title into my blog entry template. Given that 3 years have passed, it might be best to change the docs to match reality.

a year ago Edit

I'm sorry, this is now fixed

a year ago Edit

Thank you!

10 months ago Edit

Your reply