Dynamic Pages

Defining proxies

Middleman has the ability to generate pages which do not have a one-to-one relationship with their template files. What this means is that you can have a single template which generates multiple files based on variables. To create a proxy, you use the proxy method in your config.rb, and give the path you want to create, and then the path to the template you want to use (without any templating file extensions). Here's an example config.rb setup:

# Assumes the file source/about/template.html.erb exists
["tom", "dick", "harry"].each do |name|
  proxy "/about/#{name}.html", "/about/template.html", :locals => { :person_name => name }

When this project is built, four files will be output:

In most cases, you will not want to generate the template itself without the person_name variable, so you can tell Middleman to ignore it:

["tom", "dick", "harry"].each do |name|
  proxy "/about/#{name}.html", "/about/template.html", :locals => { :person_name => name }, :ignore => true

Now, only the about/tom.html, about/dick.html and about/harry.html files will be output.

Ignoring Files

It is also possible to ignore arbitrary paths when building a site using the new ignore method in your config.rb:

ignore "/ignore-this-template.html"

You can give ignore exact source paths, filename globs, or regexes.

Pretty URLs (Directory Indexes)

To use Dynamic Pages with Directory Indexes specify the proxy path followed by /index.html.

Following the example above, the proxy path would become /about/#{name}/index.html:

["tom", "dick", "harry"].each do |name|
  proxy "/about/#{name}/index.html", "/about/template.html", :locals => { :person_name => name }, :ignore => true

When this project is built, three files will be output: