Replies: 5 comments
-
Roda doesn't ship with direct support for what you want, but something like this may work for you (untested): def template_path(opts)
path = super
paths = PATHS.each
until File.file?(path)
path = super(opts.merge(views: paths.next))
end
path
end |
Beta Was this translation helpful? Give feedback.
-
Works like a charm - thank you very much 👍 I might go one step further and (mis-)use the |
Beta Was this translation helpful? Give feedback.
-
Correct, |
Beta Was this translation helpful? Give feedback.
-
Awesome - thank you again! I'll leave this here in case someone else stumbles across a similar requirement: def template_path(opts)
render_opts[:allowed_paths]
.lazy
.map { |path| super(opts.merge(views: path)) }
.find { |path| File.file?(path) }
.tap { |path| raise "Could not find template #{opts[:template]} in " +
"#{render_opts[:allowed_paths].join(":")}" if path.nil? }
end |
Beta Was this translation helpful? Give feedback.
-
I have a branch of Roda that wasn't accepted into the upstream (see: #195): https://github.com/hmdne/roda/commits/tpl_override As of now, I vendor in a version of those files in my application. |
Beta Was this translation helpful? Give feedback.
-
Given I have two apps, which have some of their templates in common (layout, flash, header, footer, not_found, etc.), is there a way to tell the
render
plugin the following instructions:Please look for
template_a
in the followingPATHS
and take the the first one you find:Ideally, I'd like to write
view "template_a"
and resolve the actual template transparently based on the contents of the two (or more) directories.I've had a look in https://github.com/jeremyevans/roda/blob/master/lib/roda/plugins/render.rb#L774, but this seems to take the path directly from
opts[:views]
. I think I've seen the mechanics at work though, looking at howrodauth
for example provides templates for the views.Beta Was this translation helpful? Give feedback.
All reactions