Multiple files for the same template


#1

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?


#2

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?