Mastodon:
Geoffrey Meredith |
Thoughts on Technology |
Blog(posted on 12 Jul 2007)
I did find that the way that Typo managed it's template system to be quite interesting. While I was familiar with being able to programatically set the layout for a controller or the whole application, what I really wanted to do was to to be able to override any view template for a specific theme. I've done this kind of thing in PHP but I really wanted to do this "the rails way". What Typo does is quite elegant although it's a bit risky. Typo overrides the ActionView::Base function full_template_path which will produce an absolute path for a template. By default this resolves to templates in the RAILS_ROOT/apps/views directory but Typo overrides this and sets up a list of serach paths to attempt to resolve to that includes RAILS_ROOT/themes/#{themename} . There are a couple of other tricks to get stylesheets, javascript and image directories to live in the theme directory. |