Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for if_has_content_for and unless_has_content_for #40

Closed
adamjohnson opened this issue Dec 11, 2015 · 6 comments
Closed

Add support for if_has_content_for and unless_has_content_for #40

adamjohnson opened this issue Dec 11, 2015 · 6 comments
Assignees

Comments

@adamjohnson
Copy link
Contributor

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
Copy link

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

@zeroedin
Copy link
Contributor

I accept pull requests. 💯

@jasonmarkle
Copy link

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

@zeroedin
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

zeroedin commented Mar 4, 2019

Fixed in 4eea618

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants