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

How to escape include #695

Closed
marek95 opened this issue Mar 10, 2016 · 7 comments
Closed

How to escape include #695

marek95 opened this issue Mar 10, 2016 · 7 comments

Comments

@marek95
Copy link

marek95 commented Mar 10, 2016

Hi,
is it be possible to somehow escape HTML of included partial?
I tried this but there is no output

{% filter escape %} {% include "item.html" %} {% endfilter %}

is there any way to do it?
Thanks!

@carljm
Copy link
Contributor

carljm commented Mar 10, 2016

That is the way you should do it, but currently there is a bug with the filter tag not handling nested tags properly and truncating the content instead: #576

@carljm carljm closed this as completed Mar 10, 2016
@marek95
Copy link
Author

marek95 commented Mar 10, 2016

thanks! is there any way to get around it now?

@carljm
Copy link
Contributor

carljm commented Mar 10, 2016

Not any easy way that I know of :/ Block set (#656) would provide a workaround, but that's not released yet... I'll do a release right now.

@carljm
Copy link
Contributor

carljm commented Mar 10, 2016

I released 2.4.0, so you should be able to work around this with something like:

{% set itemHtml %}
  {% include "item.html" %}
{% endset %}
{{ itemHtml|escape }}

(though the use of |escape filter there may not even be necessary if autoescape is on)

@marek95
Copy link
Author

marek95 commented Mar 10, 2016

thanks for fast reply!
it does not work tho...
if i do this:

{% set itemHtml %}
  <p>hahaha</p>
{% endset %}
{{ itemHtml | escape }}

output is this (as expeced)

&amp;lt;p&amp;gt;hahaha&amp;lt;/p&amp;gt;

but with your example it does not work. btw i work with grunt plugin nunjucks-2-html and it does not throw any error... it just does not output anything

@carljm
Copy link
Contributor

carljm commented Mar 10, 2016

Sorry, I'm not sure what's going on then. Did you upgrade to the just-released nunjucks 2.4.0? If so, my example should work; we have tests for includes within a block-set. I haven't used the grunt plugin you're using.

@marek95
Copy link
Author

marek95 commented Mar 10, 2016

yes, i have upgraded, i have nunjucks 2.4.0 in node_modules folder ... when i tried that code before it has shown some error, after upgrade it did not output anything
i am tired of this... i cant find a tool that allows to escape includes in html if i need to, i wouldn't have thought that it would be such a problem ...
... anyways thanks much for help!

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