question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Escape logic tags in {% raw %}

See original GitHub issue

I know that I can use {% raw %} to escape {{ output tags }}, but it doesn’t work with {% logic tags %}. Is there a way that ninjucks would output {%? Like:

{% extends "client-base.html" %}

My use case is rather unusual: I want to use nunjucks to output Django template. I need to use nunjucks (or any other JS template engine), because I’m using webpack to build static assets and I want to “insert” dynamic script names into the Django template.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
iyncommented, May 23, 2015

If, by any chance, somebody stumbles upon similar problem [0], this is my hacky way to “solve” it: https://gist.github.com/iyn/0177e51ae7e005b19e51

I created very simple webpack plugin that processes webpack stats (object with the info about the build process, generated files etc) sends the array of files to include to nunjucks template which then generates Django template. I don’t want to write a long essay here, but long story short, I need this to use in production build, because webpack generates dynamic filenames (hash of the content) and I want to include them in the Django template automatically after every build. This is because my production scripts often change and dynamic name makes me sure that every time client sees up-to date version of my app.

[0] Too many times I have had this exact experience: https://xkcd.com/979/ 😉

0reactions
iyncommented, May 19, 2015

I tried both versions. However I realized that it’s not the problem with nunjucks but with the webpack plugin I’m using (html-webpack-plugin), nunjucks works perfectly fine. I still didn’t solve the problem, but I’m closing this issue, since it’s not related to nunjucks.

Thank you for your time and sorry for not researching the problem enough.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Liquid template language - Shopify Open Source
An overview of template tags in the Liquid template language. ... Encloses multiple tags within one set of delimiters, to allow writing Liquid...
Read more >
Built-in template tags and filters - Django documentation
This document describes Django's built-in template tags and filters. ... This is equivalent to manually applying the escape filter to each variable.
Read more >
Raw String Literal in C++ - GeeksforGeeks
Whereas, a raw string literal is a string in which the escape characters like ' \n, \t, or \” ' of C++ are...
Read more >
Jinja Documentation (3.0.x) » Template Designer ...
Minus sign at the end of {% raw -%} tag cleans all the spaces and ... or " ) you SHOULD escape it...
Read more >
How to escape liquid template tags? - Stack Overflow
it is possible to disable liquid processing engine using the raw tag: {% raw %} {% this %} {% endraw %}. will display...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found