如何以|结尾(管道)在HAML中? [英] How to let a line end with | (pipe) in HAML?

查看:46
本文介绍了如何以|结尾(管道)在HAML中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题在于,在行尾(由空格分隔)的|被识别为高级换行符的语法.如果要获取此字符作为输出怎么办?

The problem is that a | at the end of a line (seperated by whitespace) is recognized as syntax for advanced line-breaks. What to do if you want to get this character as output?

假设您要创建一个菜单,例如

Say you want to create a menu like

Section 1 | Section 2 | ...

注意:如果这正是您想要的,那就看看 是否显示链接取决于特定条件.在HAML/Ruby on Rails中,这似乎有效

Wether or not a link is shown depends on a certain condition. In HAML/Ruby on Rails this could look like which does not work

%div.menu
    -if condition1?
        #{link_to 'Section 1', section_1_path} |
    -if condition2?
        #{link_to 'Section 2', section_2_path} |
    -if condition3?
        ...

解决方法

作为一种(有点脏)的解决方法,我更改了代码:

Work-around

As a (somehow dirty) work-around I changed the code:

%div.menu
    -if condition1?
        #{link_to 'Section 1', section_1_path} #{'|'}
    -if condition2?
        #{link_to 'Section 2', section_2_path} #{'|'}
    -if condition3?
        ...

推荐答案

无需转义,只需缩进与要分隔的元素相同的缩进即可.

No need for escaping, just the same indentation than the element u want separated.

%div.menu
  -if condition1?
    #{link_to 'Section 1', section_1_path} 
    |
  -if condition2?
    #{link_to 'Section 2', section_2_path} 
    |
  -if condition3?
      ...

您可以在浏览器中尝试以下操作: 在线haml编辑器:rendera 或者 html2haml

you can try this in browser: online haml editor: rendera or html2haml

这篇关于如何以|结尾(管道)在HAML中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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