是否可以在 haml 中创建可选的父节点
我喜欢 haml,但是有一个问题一直困扰着我,即父节点可能存在也可能不存在的问题。
在下面的代码中,我想超链接一些文本,但前提是我还没有查看回复(通过部分中线程变量的存在来表示)。在这种情况下,我必须重复表达链接文本的代码。
链接文本代码似乎不符合帮助程序的条件,而且它太小了,在我看来不值得部分。在这种情况下,是否有一种简单的方法可以选择包含父节点?
.text
%h2
-if defined?(threaded)
="#{request.post_type.humanize}: #{request.title}"
-else
%a{ :href => request_path(request) }
="#{request.post_type.humanize}: #{request.title}"
提前致谢。
注意:
这个问题已经在这里得到解答:我怎样才能只写一次“文本”并同时检查path_info是否包含“A”?
IMO 中的正确答案情况是使用 content_for 块。
I love haml, but there's an issue that has always bothered me, the issue of parent nodes which may or may not be present.
In the code below I want to hyperlink some text, but only if I'm not already viewing the replies (expressed by the existence of the threaded variable in the partial). In this case I have to repeat the code that expresses the link text.
The link text code doesn't seem eligible for a helper, and it's so small it doesn't to my mind merit a partial. Is there a simple way to optionally include the parent node in this case?
.text
%h2
-if defined?(threaded)
="#{request.post_type.humanize}: #{request.title}"
-else
%a{ :href => request_path(request) }
="#{request.post_type.humanize}: #{request.title}"
Thanks in advance.
Note:
This question has already been answered here: How can I do to write "Text" just once and in the same time check if the path_info includes 'A'?
The correct answer IMO in this case is to use a content_for block.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题已经在这里得到解答:我怎样才能只写一次“文本”,同时检查path_info是否包含“A”?
在这种情况下,IMO的正确答案是使用 content_for 堵塞。
This question has already been answered here: How can I do to write "Text" just once and in the same time check if the path_info includes 'A'?
The correct answer IMO in this case is to use a content_for block.