Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
127 lines (92 sloc) 3.5 KB

Plate DSL

Any .rb files located in the lib/ directory will be automatically loaded and interpretaed with the Plate DSL.

The following options are available:


Callbacks can be used to perform custom actions during the site build process.

The callbacks currently available are:

  • Site - before_render, after_render
  • Page/Post - before_render, after_render, before_write, after_write
  • Asset - before_render, after_render, before_write, after_write

To register a callback, create a new Ruby file in the lib directory. Within that file, use the callback DSL method:

callback :site, :after_render do |site|
   puts "the site finished rendering!"

This can be used to write custom pages to your site throughout the render process. For example, you could write out a list of all tags used on your site when the site finishes loading:

Callback file for lib/tags_list.rb:

callback :site, :after_render do |site|
  site.log("Creating tag pages...")

  site.tags.each do |tag|
    page =, "/tags/#{site.to_url(tag)}/index.html", :layout => 'tag')
    page.title = "Posts tagged “#{tag}”"
    page.locals = { :tag => tag }

And here's the layout for layouts/tag.erb:

layout: default

<h1>Posts tagged &#8220;<%= tag %>&#8221;</h1>

  <% posts.tags[tag].reverse.each do |post| %>
      <a href="<%= post.path %>"><%= post.title %></a>
      <time datetime="<%='%Y-%m-%d') %>" pubdate="pubdate"><%='%B %-d, %Y') %></time>
  <% end %>

Template Engines

To register a new templating engine based on a Tilt Template, use the register_template_engine method:

# Assuming the 'rdoc' gem is installed.
require 'rdoc'
register_template_engine :rdoc, Tilt::RDocTemplate

After registering a template engine, any file ending with that extension will automatically be processed with the given class.

Asset Engines

To register a new asset template engine based on a Tilt Template, use the register_asset_engine method:

# Assuming the 'sprockets' and 'eco' gems are installed.
require 'sprockets'
require 'eco'
register_asset_engine :eco, Sprockets::EcoTemplate

After registering an asset engine, any asset file ending with that extension will automatically be processed with the given class.

Dynamic Pages

Using the write command, dynamic pages can be created and written to the destination directory.

write '/path-to-write' do
  title   "Page Title"
  content "<p>My dynamic page content.</p>"
  layout  "default"  

When a site instance is not passed into the write command, the write will happen after the site is rendered. If a site instance is passed, for example within another callback, that site is used.

For example, given a layout named tag that displays all posts for a tag, the following callback would write a summary for each tag:


callback :site, :after_render do |site|
  site.tags.each do |tag|
    write "/tags/#{site.to_url(tag)}", site do
      layout  "tag"
      locals  :tag => tag


layout: default

<h1>Posts tagged with <%= tag %></h1>

  <% site.posts.tags[tag].each do |post| %>
    <li><a href="<%= post.path %>"><%= post.title %></a></li>
  <% end %>  
Jump to Line
Something went wrong with that request. Please try again.