rotundasoftware/nunjucksify — pull request #2 by w0rm (2014-08-21 05:28:11+00:00)
Title: Resolve recoursive template dependencies

Hello! I'd like to thank you for this plugin. My usage of nunjucks is rather uncommon, I have created a custom extension that allows to do this:

File 'block.nunj'

{% block items %}default{% endblock %}

File 'test.nunj'

{% bem 'block.nunj' %}{% block items %}override items{% endblock %}{% endbem %}

File 'test.nunj' will be compiled into `

override items

`

It does so by introducing new type of node, that captures raw contents during parse, adds `{% extends %}` and compiles itself as a new template from captured contents. The problem appears when I want to use such tag inside itself and pass it the same template name:

{% bem 'block.nunj' %}
{% block items %}
{% bem 'block.nunj' %}{% block items %}override items{% endblock %}{% endbem %}
{% endblock %}
{% endbem %}

I need this to be compiled into `

override items

` but I get an error that browserify could not find module with the name 'block.nunj'.

Contents of nested `{% bem 'block.nunj' %}` are compiled inside the scope of 'block.nunj', so this block tries to require itself by using overridden `env.getTemplate` and causes browserify error.

Is there any workaround for this problem?