Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

content_tag_if

#1780

TagHelper to allows the options of a content_tag to switch based on a provided condition. This is useful when generating groups of tags or when needing a tag to react to a current condition, such as current_controller or a session variable.


content_tag_if(true, :p, 'Hello world!', :class => ['when-true', 'when-false'])
# => <p class="when-true">Hello world!</p>
content_tag_if(false, :p, 'Hello world!', :class => { :if => 'when-true', :else => 'when-false' })
# => <p class="when-false">Hello world!</p>
content_tag_if(current_page?(:controller => 'books'), :p, 'Books', :class => ['current', 'inactive'])
content_tag_if(current_page?(:controller => 'newspapers'), :p, 'Newspapers', :class => ['current', 'inactive'])
# => <p class="current">Books</p><p class="inactive"> Newspapers</p>

ps. This could also be called something like content_tag_with_binary_options, or content_tag_with_options_if.

Reported by Chris Kalafarski · January 19th, 2009 @ 02:02 AM

State: wontfix
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Pascal Ehlert
    Pascal Ehlert

    Waaay to specific to go into core. If you think someone else could use this, creating a plugin will be fairly simple.

    No offense, but strong -1 on this.

    January 27th, 2009 @ 09:59 PM

  2. Chris Kalafarski
    Chris Kalafarski

    to me this functionality seems as specific as link_to_if

    January 27th, 2009 @ 10:21 PM

  3. DHH
    DHH
    • State changed from new to wontfix

    link_to_if was also a bad idea for core, imo. It should go into a plugin as well.

    February 5th, 2009 @ 08:02 PM

  4. af001
    af001

    私の中で、総合評価のとっても低いアバアバクロホリスタークロ銀座店。アバクロは大好きなんですけどね。一昨日の東京駅付近での打ち合わせの後、散歩がてら久々に行ってきました。そしたらビックリ!相変わらアバクロず、踊っているだけの店員さんとかもいましたが、

    May 5th, 2011 @ 03:00 AM