Article tags ? In my layout ?
While carefully constructing the friendly about section earlier today, I noticed that, should an article fail to receive any tags, it would be left with an annoying "Tags:" text and, misleadingly enough, no tags. This makes various baby animals the world over quite sad indeed, so it must be fixed.
My first idea was to dive into the layout and try something to the tune of :
Please note that if anybody tries making sense and pointing out that there is no sane reason why an article wouldn't be tagged, i will make up at least 20 reasons, one of which will involve string theories and pandas. You have been warned.
Shameful later edit
Thanks to Cristi i now know what the right way to go about the above problem would have been, namely
My first idea was to dive into the layout and try something to the tune of :
{% unless article.tags.empty? %} Tags: {{ article | linked_tag_list }}{% endunless %}
While this did not actually do anything useful, it did bring to light the fact that my understanding of liquid is laughable, at best. Grep safely in hand, i went deeper and came across this lovely piece of code in 'app\drops\article_drop.rb':
def initialize(source, options = {})
super source
@options = options
@liquid.update \
'body' => @source.body_html,
'excerpt' => (@source.excerpt_html.blank? ? nil : @source.excerpt_html),
'accept_comments' => @source.accept_comments?,
'is_page_home' => (options[:page] == true)
end
Being the horrible person that I am, I added
'tagged' => !@source.tags.empty?,Luckily enough, the universe didn't collapse and i could now use
{% if article.tagged %} Tags: {{ article | linked_tag_list }}{% endif %}
Please note that if anybody tries making sense and pointing out that there is no sane reason why an article wouldn't be tagged, i will make up at least 20 reasons, one of which will involve string theories and pandas. You have been warned.
Shameful later edit
Thanks to Cristi i now know what the right way to go about the above problem would have been, namely
{% unless article.tags == empty %} Tags: {{ article | linked_tag_list }}{% endunless %}

Sorry, comments are closed for this article.