Forum: Ruby on Rails Multiple files for the same template

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
List R. (Guest)
on 2005-12-07 08:31
Is there anyway to create an ERb/.rhtml template, telling it to try to
include the contents of another file, and, if not, fallback to a
default?

More specifically, I have the site running under multiple "skins", for
different brand names.  I can illustrate this with an example:

I might have in views:
/views/order/pizza.rhtml
/views/order/coke.rhtml

Now, I may have customized pizza.rhtml for one customer, but not for the
other.  So, I'd like rails to first try looking for pizza.rhtml in
/views/customized/joespizza/order/pizza.rhtml, and, if it's not there,
look in the regular /views/order/pizza.rhtml.

Any good way to do this?
List R. (Guest)
on 2005-12-11 03:59
One thing I'm working on is as follows:

1) Add a constant BRAND, in the environment
2) Change the template path to be /BRAND/...
3) Catch MissingTemplate exceptions
4) If the BRAND appears in the path, remove it and retry, else, rethrow

What does eveyone think?
Where should this code go in a plugin?  (IE, into which class/method)

lstrecv wrote:
> Is there anyway to create an ERb/.rhtml template, telling it to try to
> include the contents of another file, and, if not, fallback to a
> default?
>
> More specifically, I have the site running under multiple "skins", for
> different brand names.  I can illustrate this with an example:
>
> I might have in views:
> /views/order/pizza.rhtml
> /views/order/coke.rhtml
>
> Now, I may have customized pizza.rhtml for one customer, but not for the
> other.  So, I'd like rails to first try looking for pizza.rhtml in
> /views/customized/joespizza/order/pizza.rhtml, and, if it's not there,
> look in the regular /views/order/pizza.rhtml.
>
> Any good way to do this?
This topic is locked and can not be replied to.