Skip to content

Instantly share code, notes, and snippets.

@tarlepp
Last active May 17, 2020 16:27
Show Gist options
  • Select an option

  • Save tarlepp/f3983930c25a39f56d2cea33e0ffb74c to your computer and use it in GitHub Desktop.

Select an option

Save tarlepp/f3983930c25a39f56d2cea33e0ffb74c to your computer and use it in GitHub Desktop.
{% extends "base.html.twig" %}
{% block javascripts %}
<pre>{{ json }}</pre>
<pre>{{ json | raw }}</pre>
<script>
var foo = {{ json | raw }}
console.log(foo);
alert(foo);
</script>
{% endblock %}
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends AbstractController
{
/**
* @Route("/", name="default")
*/
public function index()
{
return $this->render('default.twig', ['json' => json_encode(['foo' => 'bar', 'bar' => 'foo'])]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment