在HAML中导入HTML片段? [英] Import HTML snippets in HAML?

查看:164
本文介绍了在HAML中导入HTML片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将HTML片段或HAML片段导入类似于PHP include 的HAML文件?

Is there a way to import HTML snippets or HAML snippets into a HAML file similar to a PHP include?

基本上有不同模块(导航,页脚,传送带等)的HTML片段可以导入到haml文件中,因此当haml文件被转换为HTML文件时(分别为nav.haml和footer.haml等) ,导入的HTML文件也被翻译过。

Basically have snippets of HTML for different modules (navigation, footer, carousels, et) in separate files (nav.haml, footer.haml, etc) that can be imported into haml files, so when the haml files are translated into HTML, the imported files HTML is translated as well.

示例:

Example:

body  
    import(path/to/nav.haml)  
    .container  
        HAML CODE   
    import(path/to/footer.haml)


推荐答案

是的,先生。

Yes, sir. It's called a partial.

body
  =render 'nav'
  .container
    -# HAML CODE
  =render 'footer'

按照惯例,partials会遵循这个命名下划线前缀:

By convention, partials would follow this naming with the underscore prefix:

_nav.html.haml
_footer.html.haml
index.html.haml

这篇关于在HAML中导入HTML片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆