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

Default for contentblock #19

Open
k-funk opened this issue Sep 1, 2016 · 3 comments
Open

Default for contentblock #19

k-funk opened this issue Sep 1, 2016 · 3 comments

Comments

@k-funk
Copy link

k-funk commented Sep 1, 2016

This is a very common patter in my project:

{% contentblock custom_main_header %}
{% ifnothascontent custom_main_header %}
  {% include header.html %}
{% endifnothascontent %}

Seems necessarily bulky just to have a default block that sub-layouts can overwrite. Is this a problem you've considered solving, or do you have an alternative way to write it?

@rustygeldmacher
Copy link
Owner

Thanks for the suggestion @k-funk -- this does seem like a common use case. I wonder if it makes sense to have contentblock support being a block element that can have its own content that will be put in place if there is no content for the block. So in your example maybe something like this:

{% contentblock custom_main_header %}
  {% include header.html %}
{% endcontentblock %}

I wonder though if Liquid supports having an optional closing or not -- if it doesn't maybe we could all it something like contentblock_or_default:

{% contentblock_or_default custom_main_header %}
  {% include header.html %}
{% endcontentblock_or_default %}

Thoughts?

@k-funk
Copy link
Author

k-funk commented Sep 12, 2016

The first example is decent.

Personally I find that jinja/django is the simplest pattern for implementing a default block: http://jinja.pocoo.org/docs/dev/templates/#template-inheritance

@rustygeldmacher
Copy link
Owner

rustygeldmacher commented Jan 16, 2017

Note to self, we can probably get the first one done by using the approach described here http://stackoverflow.com/questions/19868301/liquid-custom-tag-block-tag-with-optional-closing-tag

Also, could maybe add an else clause for ifhascontentblock by using the approach here https://github.com/Shopify/liquid/blob/master/lib/liquid/tags/if.rb#L32

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

No branches or pull requests

2 participants