Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
205 lines (140 sloc) 5.14 KB

User Templates

Buckets uses hbs (a version of Handlebars optimized for Express) as its template engine. Additionally, we load Swag by default, which provides a lot of convenient Helpers.

Alpha Notice: Buckets is in Alpha stage and some features listed below may not be implemented yet. Help decide how templates shape up.

Special Templates

  • layout.hbs: Will automatically wrap any other template that’s served. Useful for adding global header and footer elements to the page.
  • error.hbs: Buckets will automatically attempt to render the error page if it encounters either a missing Route (404) or encounters an error (500). It’s recommended to not use the entries tag within the error template.

Both of these templates are included by default.



Basic syntax:

  {{#is ‘’}}
     By Dave
     Guest Author
  <div class="warn">Sorry, no entries available yet.</div>


Parameters can be added to the tag like so:

{{#entries limit=3 bucket="products"}}
  • bucket: Pass the slug of a Bucket to filter entries. Pass multiple Buckets with a pipeline separator, eg. bucket="products|articles".
  • limit: Limit the number of entries returned.
  • skip: Combine this with the limit parameter to create pagination.
  • where: Pass a string like, where="year > 2013 && (price < 10 || onSale)" using the custom attributes of your Bucket. Note: This has negative performance implications, though it provides a very powerful search mechanism. This is not implemented yet, though you can use it with a wacky format like, where="this.content.year > 2013"
  • since: Only show entries that were published after the date provided.
  • until: Only show entries that were published before the date provided.
  • sort: Use a mongoose-style sort string, eg. sort="-publishDate", sort="lastName firstName"
{{#entries limit=10}}


This tag works with our Cloudinary image FieldType. Just pass it the image field from your Entry, and set any optional attributes via Cloudinary. For example, assuming we have a field called headshot on our "Team members" bucket, we can create a of headshots for our team with the following:

  {{img headshot alt="Image of " width="150" height="150" crop="crop" gravity="face"}}

Notice that Cloudinary gives Buckets the ability to dynamically render images in various sizes/formats, apply effects like saturation, and manipulate cropping/scaling options. Learn more about all of the Cloudinary image transformations possible.


Renders the time (in ms) the page has taken to render (best to place near the footer).



Can change the status code sent to the browser as a response. Buckets sends 200/OK by default for any rendered template.

{{#entries slug=req.params.slug}}
  {{statusCode 404}}
  <h2>Couldn’t find entries</h2>


Shows a formatted time using Moment.js. Check out the docs to see what formats are available.

{{formatTime publishDate format="MMM D, YYYY h:mma"}}


Shows the difference between the date given and now.

{{timeAgo "2014-01-01 00:00:00"}}


Passes through to the next matching Route. Best used in conjunction with entries tag like so:


Note: All of these parameters are also supported by the Buckets REST API.


Good for hiding email addresses from spammers.

Contact us at {{munge ''}}


Pretty-prints an object for debugging. Automatically HTML-encodes values.

{{inspect req}}

Global variables

Basic global object passed to every Template:


An object of data about the current page request.


The body object of data from POST requests (values received when forms are submitted).

<form method="POST">
  <input type="text" name="foo">
  {{#if req.body}}
    You submitted {{}}


The current request URL.


An object of query parameters (id. "?foo=bar" on the URL).

<a href="/?clicked=true">Click Me</a>
{{#if req.query.clicked}}
  You clicked it!


An object of parameters passed through the Route’s URL

<a href="/?clicked=true">Click Me</a>
{{#if req.query.clicked}}
  You clicked it!


The slug of your Buckets admin.

<a href="/{{adminSegment}}/">Sign In</a>


An object of data about the current Buckets user.

You are currently logged in as {{}}