Use Twig tags with React Js

1

I'm using Django that uses Twig to render the templates.

What I want to do is put an item that Django uses in the React code as follows:

var usuario = {{usuario}};

But he will not let me. There is not any kind of tag {verbatim} that cancels the '{' and '}' tags of React (as Django has)?

Thank you very much

    
asked by Genarito 24.11.2016 в 00:46
source

1 answer

1

I solved the problem, I generated a <script> in my HTML where I declare the variables I need, such as:

<script>
    var nombreDeUsuario = {{usuario_nombre}};
    // Declaro el resto de las variables...
</script>
<script>
    // Codigo react usando las variables arriba declaradas
</script>

Even works with tags like

var urlDeSeccion = "{% url 'seccion' %}";
    
answered by 17.01.2017 / 16:49
source