[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Getting PHP/Smarty template functionality from Ruby or Ruby on Rails

Irving Fried

10/15/2006 3:40:00 AM

I've read about Canny, but it doesn't seem to enjoy a lot of versions or
users since it's been released. I've read that Ruby natively supplies
template functionality. I need to know how easy it will be with Ruby to
re-skin a webapp. Also, whether Ruby or Ruby on Rails would be
preferable in this situation?

Note, I'm not looking for simple JSP functionality, but the ability to
go beyond that by having Ruby select a specific template at runtime, the
way I can do with Smarty. I want to abstract the template away so that
the end user will get the same URL regardless of the skin that's used to
display it.

I'd appreciate whatever advice you can give.
2 Answers

Jeremy Hubert

10/15/2006 5:30:00 AM

0

Hi Irving,

It's fairly simple to get the same functionality as Smarty.

In your application controller, just add:

before_filter :set_theme

private

def set_theme
ActionController::Base.template_root = File.join(RAILS_ROOT, 'app/
views', theme) if theme
end

def theme
session[:theme] = params[:theme] if params[:theme]
session[:theme]
end

That would allow you to place a folder in your app/views directory
with the name of your theme, and Rails will automatically load the
views from that folder instead.

If you'd like to place them in a separate folder, just change this:

def set_theme
ActionController::Base.template_root = File.join(RAILS_ROOT,
'themes', theme) if theme
end

This will allow you to create theme directories in the root of your
application.

Note that this will move the theme routing, so you will need to have
duplicates of all the theme files in the theme folder. There are
other ways to do it so that it only uses the themed version if the
file exists, which allows you to set themed portions and leave the
bulk of your app alone.

As far as a template language goes, check out liquid: http://
home.leetsoft.com/liquid

Best of luck,
Jeremy Hubert

On 14-Oct-06, at 8:45 PM, Irving Fried wrote:

> I've read about Canny, but it doesn't seem to enjoy a lot of
> versions or users since it's been released. I've read that Ruby
> natively supplies template functionality. I need to know how easy
> it will be with Ruby to re-skin a webapp. Also, whether Ruby or
> Ruby on Rails would be preferable in this situation?
>
> Note, I'm not looking for simple JSP functionality, but the ability
> to go beyond that by having Ruby select a specific template at
> runtime, the way I can do with Smarty. I want to abstract the
> template away so that the end user will get the same URL regardless
> of the skin that's used to display it.
>
> I'd appreciate whatever advice you can give.
>




Irving Fried

10/15/2006 11:32:00 AM

0

Brilliant. Thank you. So it sounds like Canny is unnecessary. I
wonder why Canny was created.

By the way, can I get that same functionality from Ruby and Ruby on Rails?