Nested blocks don't render properly #3

Open
tbak42 opened this Issue Feb 7, 2012 · 5 comments

Comments

Projects
None yet
4 participants

tbak42 commented Feb 7, 2012

If you have a block inside of another block, it will not render properly if you then redefine it in another file.

Example!


_base.liquid:
{% block test_a %}
Top of A
{% block test_b %}
This should be replaced
{% endblock %}
Bottom of A
{% endblock %}


foo.liquid:
{% extends "base" %}
{% block test_b %}
REPLACED TEST_B
{% endblock %}


The text output should be:
Top of A
REPLACED TEST_B
Bottom of A

But instead it is:
Top of A
This should be replaced
Bottom of A

I think that the expected behavior is what the Django template system does...

tbak42 commented Feb 9, 2012

Hmm I think this may be unrelated to nested blocks. I think it's caused by the Block::Liquid::Block using a regex that only extracts a single character when naming the block, so there are naming collisions. I think Syntax should be

/(\w+)/

instead of

/(\w)+/

that seems to fix the problem for me! :)

I've tried checking out and manually rake installing some of the forks of this repo but even those that fix this regex don't seem to solve the problems of nested tags.

I'm trying to use this gem with Jekyll and some help from http://www.sameratiani.com/2011/10/22/get-jekyll-working-with-liquid-inheritance.html to make the file system work.

I've got

parent.html

<html>
{% block content %}{% endblock %}
</html>

child.html

{% extends parent %}
{% block content %}
  here comes foo:
  {% block foo %} {% endblock %}
{% endblock %}

mypage.html

{% extends child %}
{% block foo %} bar {% endblock %}

What i'd expect:

<html>
here comes foo:
bar
</html>

What I get:

<html>
here comes foo:
</html>
bar

For example the borntyping fork appears to fix the regex: https://github.com/borntyping/liquid-inheritance/commit/3de7f29690dc6e8af74a45efeea819d438c12a70 but it's still not working.

Am I fundamentally misunderstanding django blocks here or jekyll perhaps, or is that template_load code at fault?

FWIW I've posted a stackoverflow question on this too, on the off-chance that i've got completely the wrong end of the stick and this regex isn't actually the issue: http://stackoverflow.com/questions/13086569/jekyll-templates-using-django-like-liquid-blocks-inheritance

I have a fix for this as soon as I get chance I will submit - is a minor change.

Any updates on this issue @neilkinnish @davecranwell ?

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