You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've faced quite strange, and a bit nontrivial issue.
it seems that there is no way to output content of caller() as raw (same as {% raw %} block and in same time as rendered.
Sounds a bit weird, so let me just show.
We have a macro, which accepts some code as input, and outputs example, which used as part of codestyle/codeguide, etc.:
{## # Display provided code as an example # # @param {string} title Title of example # # @return {string} Complex html with example #}{%macroexample(title) %}
<p>{{ title }}</p>
{# Here we outputting rendered version, for preview #}
<div>{{ caller() }}</div>
{# And here we're outputting code as it is, so that visitor could see it on page #}
<div>
<pre><code>{{ caller()|escape }}</code></pre>
</div>
{%endmacro%}
And this worked for html quite well.. However, it obviously won't work if you want to print Nunjucks code as an example.
will output <p>Content of Nunjuks expression}</p> in <code> while we want to get <p>{{ 'Content of Nunjuks expression' }}</p>.
To solve that issue we have {% raw %} block... but irony is that we can't use it here. If we will wrap caller() with raw block, we will get... yes... {{ caller() }}.
And if we will try to use {% raw %} in {% call %} it won't work too, because we will get raw output in place, where we want to get rendered preview.
Of course there is nothing wrong with it and it's obviously should work that way, but I just can't figure out good way to workaround it.
{%macroexample(title) %}
<p>{{ title }}</p>
{# Here we outputting rendered version, for preview #}
<div>{{ caller()|renderCaller }}</div>
{# And here we're outputting code as it is, so that visitor could see it on page #}
<div>
<pre><code>{{ caller()|escape }}</code></pre>
</div>
{%endmacro%}
I just wonder, maybe someone knows more elegant and not that hacky way to solve that issue?
Seems like raw filter would be best candidate for that role, but even Jinja doesn't have such. And after I've checked macro's caller() output it started to be clear why — caller getting already compiled content, so you can't output it in raw form from there. Though, I don't know is it just a Nunjucks caller() receives already compiler content, or in Jinja it's done in different way.
The text was updated successfully, but these errors were encountered:
I've faced quite strange, and a bit nontrivial issue.
it seems that there is no way to output content of
caller()
as raw (same as{% raw %}
block and in same time as rendered.Sounds a bit weird, so let me just show.
We have a macro, which accepts some code as input, and outputs example, which used as part of codestyle/codeguide, etc.:
And this worked for html quite well.. However, it obviously won't work if you want to print Nunjucks code as an example.
This
will output
<p>Content of Nunjuks expression}</p>
in<code>
while we want to get<p>{{ 'Content of Nunjuks expression' }}</p>
.To solve that issue we have
{% raw %}
block... but irony is that we can't use it here. If we will wrapcaller()
with raw block, we will get... yes...{{ caller() }}
.And if we will try to use
{% raw %}
in{% call %}
it won't work too, because we will get raw output in place, where we want to get rendered preview.Of course there is nothing wrong with it and it's obviously should work that way, but I just can't figure out good way to workaround it.
So far what I've done:
Added
{% raw %} block inside
{% call %}`Wrote special filter, which forces second render of output of
caller()
:Used it on
caller()
with code preview:I just wonder, maybe someone knows more elegant and not that hacky way to solve that issue?
Seems like
raw
filter would be best candidate for that role, but even Jinja doesn't have such. And after I've checked macro'scaller()
output it started to be clear why — caller getting already compiled content, so you can't output it in raw form from there. Though, I don't know is it just a Nunjuckscaller()
receives already compiler content, or in Jinja it's done in different way.The text was updated successfully, but these errors were encountered: