【问题标题】:How to use partials in Slim templates如何在 Slim 模板中使用局部变量
【发布时间】:2014-10-24 19:50:33
【问题描述】:

有没有办法将_header.slim_footer.slim 放在单独的文件中并将它们注入到其他(主)slim 文件中?

我正在构建这样的模板:

def slim(template, context = nil)
  Slim::Template.new { template }.render(context)
end

def template(name)
  File.read(Notifications.root.join "notifications/templates/#{name}.slim")
end

当我注入 slim('_header.slim') 或仅注入 template('_header.slim') 时,它会在我的主布局中呈现为纯文本。

有什么办法吗?

【问题讨论】:

  • 您可以尝试使用html_safe 来查看html 输出而不是计划文本。

标签: ruby-on-rails ruby templates slim-lang


【解决方案1】:

解决方案非常简单。

输出没有 HTML 转义 ==

与单个等号 (=) 相同,但不通过 escape_html 方法。对于尾随或前导空格,支持修饰符 ><

  • 输出没有 HTML 转义和尾随空格 ==>。与双等号 (==) 相同,只是它添加了一个尾随空格。还支持旧语法 =='
  • 输出没有 HTML 转义和前导空格 ==<。与双等号 (==) 相同,只是它添加了前导空格。

https://github.com/slim-template/slim#output-without-html-escaping-

【讨论】:

    猜你喜欢
    • 2019-07-22
    • 2019-01-05
    • 2019-05-25
    • 1970-01-01
    • 2016-08-07
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    相关资源
    最近更新 更多