在我的一个模型中,我有一个发送电子邮件的方法.我想通过Haml文件标记此电子邮件,该文件与我的其他视图一起存储.
有没有办法从模型中调用Sinatra的HAML帮助器?如果没有,我需要直接打电话给Haml:
@name = 'John Doe'
Haml::Engine.new(File.read("#{MyApplication.views}/email.haml")).to_html
Run Code Online (Sandbox Code Playgroud)
Haml模板有没有办法访问@name实例变量?
小智 5
尝试这样的事情:
tmpl = Tilt.new("#{MyApplication.views}/email.haml")
tmpl.render(self) # render the template with the current model instance as the context
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!