wvuweb / hammer

A tool for CleanSlate theme development
https://cleanslate.wvu.edu
4 stars 2 forks source link

Add support for if_has_content_for and unless_has_content_for #40

Closed adamjohnson closed 8 years ago

adamjohnson commented 8 years ago

These tags make it easier to only display an editable region & the region's surrounding tags if there is content that has been added to it.

Code Example:

<r:page:if_has_content_for region="region_name" always_show_in_edit_mode="true">
  <div class="foobar">
    <h1>I will always show in edit mode and only show this heading in production <em>if</em> there's content in this editable region.</h1>
    <r:editable_region name="region_name" />
  </div>
</r:page:if_has_content_for>

Here's unless_has_content_for aka if_doesnt_have_content_for:

<r:page:unless_has_content_for region="region_name">
  <div class="foobar">
    <h1>I will show if there's no content in the region named `region_name`.</h1>
  </div>
</r:page:unless_has_content_for>

Location of tags in CleanSlate source: lib/slate/radius/tags/page.rb

jasonmarkle commented 8 years ago

:+1 would love to see this sooner rather than later.

zeroedin commented 8 years ago

I accept pull requests. :100:

jasonmarkle commented 8 years ago

@zeroedin I'll try to get to it at some point. Trying to get some other stuff done before the weekend.

zeroedin commented 8 years ago

Ok an implementation note here.

Because of the differences between the CMS and hammer as a tool, you will have to duplicate your editable_region region name in your mock_data.yml file Example below:

page:
  name: "Page Name"
  ...
  content: 
    region_name_here: "Some Content"

editable_region:
  main: "Main content"
  ...
  region_name_here: "Some Content"

The way this works is that it first checks to see if the current page has the content region page:content:region_name_here and that it contains content, the region_name_here under page:content in this case could just be a boolean true or false. However if you intend to use that field elsewhere it would behoove you to just duplicate the same content. In this case because of the way radius works with "expanding" tags in hammer the inner tag does not reference the same context.

With that said, without more testing it is possible in more complex looping in pages context I'm sure there be dragons.

adamjohnson commented 8 years ago

I set region_name_here in page: to true and everything works swimmingly for simple uses of this tag.

As Steve says, if you're pulling content from one page to another, then duplicating the content in the page: key and the editable_region: key might be warranted.

zeroedin commented 5 years ago

Fixed in 4eea618c31b3958d72258751d69cecb1f50cb099