cheers,
DAZ
--
You received this message because you are subscribed to the Google Groups "sinatrarb" group.
To post to this group, send email to sina...@googlegroups.com.
To unsubscribe from this group, send email to sinatrarb+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sinatrarb?hl=en.
helpers do
def find_template(views, name, engine, &block)
super(views, name, engine, &block) # will try to render :foo
super(views, :generic, engine, &block) # if that is missing, try :generic
end
end
get '/foo' do
haml :foo
end
Note that this will use :generic for all templates. You can of course check the value of name and engine.
If you use that with a lot of different fallback templates, try something like this:
helpers do
def template_exists?(engine, name)
find_template(settings.views, name, Tilt[engine]) do |file|
return true if File.exist? file
end
false
end
end
get '/foo' do
if template_exists? :haml, :foo
haml :foo
else
haml :generic
end
end
Konstantin
This should go in contrib imo :)