![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
jinja-to-js
Advanced tools
[![Build Status](https://travis-ci.org/jonbretman/jinja-to-js.svg?branch=master)](https://travis-ci.org/jonbretman/jinja-to-js)
Converts Jinja2 templates into JavaScript functions so that they can be used in the browser.
Jinja2 is a very fast templating language and therefore is ideal for use with Python web framework like Django, however there are many use cases for wanting to share the same template between the server and the browser. Instead of writing a Jinja implementation in JavaScript (there are already a few of those) jinja-to-js uses the Python Jinja2 library to parse a template into an AST (http://jinja.pocoo.org/docs/dev/api/#jinja2.Environment.parse) and uses that AST to output a JavasScript function/module.
First install jinja-to-js using pip
:
$ pip install jinja-to-js
Lets assume we have a Jinja template called names.jinja.
{% for name in names %}
{{ name }}
{% endfor %}
We can turn this into a JavaScript module like so:
$ jinja_to_js -f ./names.jinja -o ./names.js -m es6
names.js will now contain:
export default function template(context) {
/* JS code here */
};
The -m
option specified the module type, which can be amd
, commonjs
, es6
or not provided at all which will result in jinja-to-js just outputting a named JS function.
if
statements (Jinja Docs)for
(Jinja Docs) - see below for supported loop helperswith
(Jinja Docs)include
(Jinja Docs) - see below for exampledefined
- docsundefined
- docscallable
- docsdivisibleby
- docseven
- docsodd
- docsnone
- docsnumber
- docsupper
lower
string
mapping
safe
- docscapitalize
- docsabs
- docsattr
- docsbatch
- docsdefault
- docsfirst
- docsint
- docslast
- docslength
- docslower
- docsslice
- docstitle
- docstrim
- docsupper
- docstruncate
- docsLoop helpers will only work for lists (JS arrays). The following helpers are supported:
loop.index
loop.index0
loop.first
loop.last
loop.length
Includes are supported by taking the following steps:
{% include 'bar.jinja' %}
, then you must provide a function called include
on the context object passed to the template. This function will be called with the name of the template to be included and should return the compiled version of this template.The following shows a simple example of this in practice.
var templates = {
'bar': theCompiledFnForBar,
'foo': theCompiledFnForFoo
};
function getTemplate(name) {
return templates[name.replace(/\.jinja$/, '')];
}
function render(name, context) {
context.include = getTemplate;
return getTemplate(name)(context);
}
render('foo');
Template inheritance is supported, including the {{ super() }}
function. The name of the template to be extended from must be a string literal as it needs to be loaded at compile time.
Parent
{% block content %}
The default content.
{% endblock
Child
{% block content %}
{{ super() }}
Additional content.
{% endblock %}
FAQs
[![Build Status](https://travis-ci.org/jonbretman/jinja-to-js.svg?branch=master)](https://travis-ci.org/jonbretman/jinja-to-js)
The npm package jinja-to-js receives a total of 0 weekly downloads. As such, jinja-to-js popularity was classified as not popular.
We found that jinja-to-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.