Skip to content

Instantly share code, notes, and snippets.

@dougo-chris
Created August 4, 2012 02:56
Show Gist options
  • Save dougo-chris/3253732 to your computer and use it in GitHub Desktop.
Save dougo-chris/3253732 to your computer and use it in GitHub Desktop.
How to create ghost pages with backbone templates
Why
---
My site is backbone.js and rails, including the static marketing content. I wanted this content to be readable by google and I don't want two copies.
Background
----------
I'm using the haml_assets gem so I can write backbone.js views in haml.
Routes
------
root :to => "pages#home"
controller :pages do
get 'site' => :home
get 'site/:template' => :site
post 'enquiry' => :enquiry
end
Controller
----------
def home
@javascript_template = 'home'
render :home
end
def site
@javascript_template = params[:template] || 'home'
render :home
end
home.html.haml
---------------
- engine = Haml::Engine.new(File.read("#{Rails.root}/app/assets/javascripts/site/template/_header.jst.ejs.haml"))
= engine.render(self)
:javascript
$(function() {
backboneStart('site/{@javascript_template}');
});
- engine = Haml::Engine.new(File.read("#{Rails.root}/app/assets/javascripts/site/template/page/#{@javascript_template}.jst.ejs.haml"))
= engine.render(self)
_header.jst.ejs.haml
--------------------
/ all links have a fallback site template to link to for website crawlers to visit
/ The view should capture this (ie.,click #anonBenefit ...)
%a.brand#anonHome{href: '/'}
.left10.right10
T4Manager.com
%ul.nav
%li
%a#anonBenefit{href: '/site/benefit'}
.left10.right10
Benefits
%li
%a#anonFeature{href: '/site/feature'}
.left10.right10
Features
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment