I am trying to use the BoostrapBundle for Symfony2, but I get stuck.
I tried to install the assets and use assetic using the tutorial, but I don't know how to use it on a twig file.
I tried with:
{% javascripts '@BcBootstrapBundle' %}
<script type="text/javascript" src="{{ bootstrap_js }}"></script>
{% endjavascripts %}
But I get the error:
An exception has been thrown during the compilation of a template ("There is no "BcBootstrapBundle" asset.")
According to the manual:
When you have AsseticBundle installed BootstrapBundle will automatically configure the assets from Twitter Bootstrap for you. If you want to change the configuration you can do this by overwritting the Assetic configuration.
But there's nothing about the good syntax to use on a twig file, even in the BootstrapDemoBundle (if you look at the source code, you'll see a use Assetic
comment, but it doesn't help).
In the next section, they give an usage example which is supposed to use bootstrap, but it looks like there is something missing.
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="{{ asset('css/bootstrap.css') }}">
</head>
<body>
<h1>Hello, world!</h1>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="{{ asset('js/jquery.js') }}"><\/script>')</script>
<script src="{{ asset('js/bootstrap.js') }}"></script>
</body>
</html>
They use a simple {{ asset('file') }}
, who points web/
directory (but I never put any file there, and so didn't assets:install
).
So my question is:
How to use the preconfigured assets to create a bootstrapped view?
You should dump the assets first using assetic:dump. This command will generate the files you need and then you can include them with the asset(...)
function.