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.
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.