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

I

Irving Fried

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.
 
J

Jeremy Hubert

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
 
I

Irving Fried

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top