[英]Haml: more elegant way to write tag + ruby-expression + string
I've got the following haml-code in one of my templates: 我的模板之一中包含以下haml代码:
%b= t ('activerecord.attributes.exercise.title') + ':'
Is there a more elegant way to achieve this? 有没有更优雅的方法来实现这一目标? Preferrably as oneliner and without the brackets. 最好是作为一个内衬,且不带括号。
这样看起来好点吗?
%b #{t 'activerecord.attributes.exercise.title'}:
The solution I like to use is Haml's surround
, succeed
, and precede
helpers: 我喜欢用的解决方案是Haml的的surround
, succeed
,并precede
助手:
= surround '(', ')' do
= link_to 'available here', foo_path
= precede '*' do
= link_to 'source', foo_path
= succeed ':' do
= link_to 'foo', foo_path
Text following link
Then it's just typing/pasting a line before the helper and indenting the helper. 然后,它只是在帮助程序之前键入/粘贴一行并缩进该帮助程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.