How to make views changable


#1

Hello

I need to make site views changeable
I found how to change layouts but it is not enough, becouse templates
can use different ways to display and organize content.
I found one way to do this, but i need to make subfolders in my
‘view/layouts’, ‘view/controller_name’ both and to create additional
subfolder somewhere in ‘public’ to put there tepmlate images, styles, js
etc.

Is there any options to tell rails to look for views in the other
places, not in ‘app/view’ ?


#2

why not put images, styles and js in the appropriate folders that exist
already? (Except the images one… you would need to create that one)


#3

the problem is not in place for images
i just want to have all files related to some template in one folder
maximum 2 folders
1 - for views and layouts
2 - public folder for images and other browsable things

in php whith smarty it would be something like that
$smarty->templates_dir = “/path/to/my/templates”
so
$smarty->display(“index.tpl”)
will render
/path/to/my/templates/index.tpl

but rails somehow knows that all views are in /rails/app/view
is it passible to change this path inside the controller dinamicly ?


#4

On Apr 27, 2006, at 1:46 AM, Łukasz Piestrzeniewicz wrote:

$smarty->display(“index.tpl”)
will render
/path/to/my/templates/index.tpl

but rails somehow knows that all views are in /rails/app/view
is it passible to change this path inside the controller dinamicly ?

It’s quite simple. In your controller just put:

@response.template.base_path = “/absolute/path/to/template/root”

Please don’t do that!

At the very least, make a CONSTANT in config/environment.rb and
use that rather than a string somewhere in your source code.

Better yet, figure out a way to handle it relative to RAILS_ROOT
so that if you move your app around in the filesystem, it will
still work.


– Tom M.


#5

Kostya wrote:

the problem is not in place for images
i just want to have all files related to some template in one folder
maximum 2 folders
1 - for views and layouts
2 - public folder for images and other browsable things

in php whith smarty it would be something like that
$smarty->templates_dir = “/path/to/my/templates”
so
$smarty->display(“index.tpl”)
will render
/path/to/my/templates/index.tpl

but rails somehow knows that all views are in /rails/app/view
is it passible to change this path inside the controller dinamicly ?

It’s quite simple. In your controller just put:

@response.template.base_path = “/absolute/path/to/template/root”
render(:action => ‘index’)

(see:
http://ragnarson.blogspot.com/2006/04/dynamic-templateroot-revisited.html
and http://ragnarson.blogspot.com/2006/03/dynamic-templateroot.html)

But do not be tempted to put everything (templates, images) in one
place. It is a very bad decission. Rather get used to current setup.

Remember, that generated html code should be strictly semantical and
site look should be defined by CSS. In that sense html is completly
unrelated to visual effect (see http://csszengarden.com for examples).

Cheers,
Łukasz