# ActionView theme hack?

**URL:** <https://www.ruby-forum.com/t/actionview-theme-hack/111161>\
**Category:** Rails\
**Created:** [August 3, 2007, 10:32am UTC](https://www.ruby-forum.com/t/actionview-theme-hack/111161 "2007-08-03T10:32:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [August 3, 2007, 10:32am UTC](https://www.ruby-forum.com/t/actionview-theme-hack/111161/1 "2007-08-03T10:32:09Z")

</div>

Hey guys

I am needing to implement a theme type functionality in my app, I guess  
one thats similar in operation to the way typo works with the theme  
.rhtml files override the default view behavior. I found this blog post  
about how the typo implementation works:

> **[Typo theme engine :: scottstuff.net](https://scottstuff.net/blog/articles/2005/11/08/typo-theme-engine/index.html)**
>
> Typo has had theme support since before Typo 2.5.0 was released, but the first version of Typo’s theme engine didn’t include the ability for themes to change any of the HTML generated by Typo’s views. Themes could change CSS, graphics, and the...

However when you look at hte source for the newest version, the  
methodology for how it works seems te be very different and they dont  
use that hack anymore. Would someone be able to lend an insight as to  
why/how the current implementation works, as its tottally not obvious!  
There are notes in the source that there overideing undocumented rails  
methods, but even when comparing there overrides with the rails source  
itself, things dont become clear!

Any advice on implementing a themeing system would be greatly  
appreciated 🙂

Cheers

-Tim

---

<div class="post-metadata">

**Author:** ![timperrett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@timperrett](https://www.ruby-forum.com/u/timperrett)\
**Post date:** [August 3, 2007, 1:57pm UTC](https://www.ruby-forum.com/t/actionview-theme-hack/111161/2 "2007-08-03T13:57:00Z")

</div>

Ahh I did it 🙂

For anyone who is interested, its purley a matter of having the  
following in a helper file:

# NB: This overrides an undocumented rails function in order to add

# a search path. We need this to get themes working, but I’d be

# happier if we didn’t have to override undocumented methods. Ho

# hum. – pdcawley

def search\_paths  
["…/…/themes/#{this\_site.theme.name}/views", # for normal views  
“.”,  
“…/app/views”]  
end

def full\_template\_path(template\_path, extension)  
search\_paths.each do |path|  
themed\_path = File.join(@base\_path, path,  
“#{template\_path}.#{extension}”)  
return themed\_path if File.exist?(themed\_path)  
end  
# Can’t find a themed version, so fall back to the default behaviour  
super  
end

and having the appropriately set models. Also, check out cached\_model  
project, as that is very useful for performance enhancing when calling  
the same method many times on one request.

Tim
