# REPOST: fallback layout mechanism

**URL:** <https://www.ruby-forum.com/t/repost-fallback-layout-mechanism/132172>\
**Category:** Rails\
**Created:** [March 17, 2008, 4:17pm UTC](https://www.ruby-forum.com/t/repost-fallback-layout-mechanism/132172 "2008-03-17T16:17:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![goodwill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@goodwill](https://www.ruby-forum.com/u/goodwill)\
**Post date:** [March 17, 2008, 4:17pm UTC](https://www.ruby-forum.com/t/repost-fallback-layout-mechanism/132172/1 "2008-03-17T16:17:38Z")

</div>

Sorry for reposting but as I got no reply so far so I am just coming  
to try my luck again.

I am doing a multi-lingual website which might have several layout  
pages (language dependent)available. I want to do a mechanism to fall  
back from one language to another default language if such layout  
file  
is missing. Any chance I can do an is\_exist check on the layout? With  
my current code I really want to just check it instead of catching a  
MissingTemplate error.

---

<div class="post-metadata">

**Author:** ![goodwill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@goodwill](https://www.ruby-forum.com/u/goodwill)\
**Post date:** [March 17, 2008, 4:28pm UTC](https://www.ruby-forum.com/t/repost-fallback-layout-mechanism/132172/2 "2008-03-17T16:28:45Z")

</div>

only thing i see would be to do a simple File.exist?(file\_name) on the  
layout

but i would avoid to do this, that’s more of an organizational problem  
to me, to make sure a language is fully implemented or not. if not, then  
don’t show it

or keep a hash with ‘allowed’ languages somewhere  
:en =\> true,  
:fr =\> true,  
:de =\> false etc.

this would depend on how many other parts of your site (views,  
db-entries…) need to provide a translation.

---

<div class="post-metadata">

**Author:** ![goodwill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@goodwill](https://www.ruby-forum.com/u/goodwill)\
**Post date:** [March 17, 2008, 4:41pm UTC](https://www.ruby-forum.com/t/repost-fallback-layout-mechanism/132172/3 "2008-03-17T16:41:59Z")

</div>

you mean to say u want to check for the layout file exist or not?

---

<div class="post-metadata">

**Author:** ![goodwill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@goodwill](https://www.ruby-forum.com/u/goodwill)\
**Post date:** [March 19, 2008, 10:18am UTC](https://www.ruby-forum.com/t/repost-fallback-layout-mechanism/132172/4 "2008-03-19T10:18:45Z")

</div>

Hmmm… looks good, but any chance if there is a non-default path for  
views/layouts? I think it would be great if I could just have a  
is\_template\_exist somewhere in the framework.

There are many websites would only implement a localized version for  
certain page (like a company overview) and then skip the others, its  
more a use case issue than a design issue I guess…

On Mar 17, 11:54 pm, Thorsten M. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![goodwill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@goodwill](https://www.ruby-forum.com/u/goodwill)\
**Post date:** [April 3, 2008, 2:14am UTC](https://www.ruby-forum.com/t/repost-fallback-layout-mechanism/132172/5 "2008-04-03T02:14:31Z")

</div>

On Mar 19, 4:18 am, goodwill [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hmmm… looks good, but any chance if there is a non-default path for  
> views/layouts? I think it would be great if I could just have a  
> is\_template\_exist somewhere in the framework.
> 
> There are many websites would only implement a localized version for  
> certain page (like a company overview) and then skip the others, its  
> more a use case issue than a design issue I guess…

I was wondering about this same thing in terms of having a simple  
“theme engine” of sorts. You could add “themes” to an app simply by  
having an override ability. So, if a file existed in /themes/users/  
index.html.erb it could be set to override the one in /app/views/users/  
index.html.erb…?

---

<div class="post-metadata">

**Author:** ![goodwill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@goodwill](https://www.ruby-forum.com/u/goodwill)\
**Post date:** [March 17, 2008, 4:54pm UTC](https://www.ruby-forum.com/t/repost-fallback-layout-mechanism/132172/6 "2008-03-17T16:54:58Z")

</div>

yes,

File.exist?(File.join(RAILS\_ROOT, “app”, “views”, “layouts”,  
“lang\_en.html.erb”))

would give you a true or false, so you can decide what to do about it  
it’s a bit primitive, but i can’t come up with a rails internal method  
for layouts, so that would be what i would do if i had to.

but it would depend on lot’s of other details, i would avoid (as  
mentioned) to do things on that level, maybe keeping the translations in  
the db and deciding in the layout file, what to render.

do you really want to have different layouts or is the layout the same  
(colors, positions…) and only the texts change?  
what’s about other language dependent parts? like views or stuff in the  
db? error messages?

can you allow to implement a language in parts? i would go for all or  
nothing here, either a language exists and can be used without double  
checking everything or not. but it’s up to you to decide

---

<div class="post-metadata">

**Author:** ![goodwill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ac8455/32.png) [@goodwill](https://www.ruby-forum.com/u/goodwill)\
**Post date:** [April 3, 2008, 2:36am UTC](https://www.ruby-forum.com/t/repost-fallback-layout-mechanism/132172/7 "2008-04-03T02:36:10Z")

</div>

On Apr 2, 7:13 pm, Trevor T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I was wondering about this same thing in terms of having a simple  
> “theme engine” of sorts. You could add “themes” to an app simply by  
> having an override ability. So, if a file existed in /themes/users/  
> index.html.erb it could be set to override the one in /app/views/users/  
> index.html.erb…?

Hmm… perhaps this would do the trick?

[http://weblog.rubyonrails.com/2007/2/4/new-feature-for-rails-2-0-multiple-controller-view-paths](http://weblog.rubyonrails.com/2007/2/4/new-feature-for-rails-2-0-multiple-controller-view-paths)
