nunjucks

How can I define global variables in nunjucks?

 ̄綄美尐妖づ 提交于 2019-12-01 01:54:46
问题 Using nunjucks, how can I define some global variables that should always be available within all templates? Ideally, they would be specified somewhere in the environment or config options and not have to be merged into the context dict with each call to nunjucksEnvironment.render . 回答1: I was just looking for this and came here. Looks like there's now a recommended way which was added in recently in version 1.0.6. See Environment.addGlobal. 回答2: It's not documented (or perhaps advised), but

How to execute a (safe) bash shell command within setup.py?

余生颓废 提交于 2019-12-01 00:19:27
I use nunjucks for templating the frontend in a python project. Nunjucks templates must be precompiled in production. I don't use extensions or asynchronous filters in the nunjucks templates. Rather than use grunt-task to listen for changes to my templates, I prefer to use the nunjucks-precompile command (offered via npm) to sweep the entire templates directory into templates.js. The idea is to have the nunjucks-precompile --include ["\\.tmpl$"] path/to/templates > templates.js command execute within setup.py so I can simply piggyback our deployer scripts' regular execution. I found a

Gulp Front Matter +Markdown through Nunjucks

淺唱寂寞╮ 提交于 2019-11-30 05:04:12
问题 I'm working on adding some simple Markdown processing to my Gulp process, but I can't quite get the pieces to work together. I seem to be missing the step between getting the front matter content, and determining which Nunjuck template to apply. Here's the section in my Gulp file: gulp.task('pages:md', function() { gulp.src('./content/**/*.md') .pipe(frontMatter({ // optional configuration property: 'frontMatter', // property added to file object remove: true // should we remove front-matter

Convert integer to string Jinja

别说谁变了你拦得住时间么 提交于 2019-11-28 18:30:21
I have an integer {% set curYear = 2013 %} In {% if %} statement I have to compare it with some string. I can't set curYear to string at the beginning because I have to decrement it in loop. How can I convert it? Glen Swift I found the answer. Cast integer to string: myOldIntValue|string Cast string to integer: myOldStrValue|int 来源: https://stackoverflow.com/questions/19161093/convert-integer-to-string-jinja