To simulate the rendering behavior of a Sinatra controller in some other class (not a controller), you can create a module as follows:
module ErbRender include Sinatra::Templates include Sinatra::Helpers include Sinatra::ContentFor def settings @settings ||= begin settings = Sinatra::Application.settings settings.root = "#{ROOT}/app" settings end end def template_cache @template_cache ||= Tilt::Cache.new end end
Here you may need to configure settings.root
Usage example:
class ArticleIndexingPostBody include ErbRender def get_body erb :'amp/articles/show', layout: :'amp/layout' end end
This will correctly display layout templates, including content_for
Dan key
source share