-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added an article explaining how to use Bower in Symfony #5159
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
.. index:: | ||
single: Front-end; Bower | ||
|
||
Using Bower with Symfony | ||
======================== | ||
|
||
Symfony and all its packages are perfectly managed by Composer. Bower is a | ||
dependency management tool for front-end dependencies, like Bootstrap or | ||
jQuery. As Symfony is purely a back-end framework, it can't help you much with | ||
Bower. Fortunately, it is very easy to use! | ||
|
||
Installing Bower | ||
---------------- | ||
|
||
Bower_ is built on top of `Node.js`_. Make sure you have that installed and | ||
then run: | ||
|
||
.. code-block:: bash | ||
|
||
$ npm install -g bower | ||
|
||
After this command succeeded, run ``bower`` in your terminal to find out if | ||
it's installed correctly. | ||
|
||
.. tip:: | ||
|
||
If you don't want to have NodeJS on your computer, you can also use | ||
BowerPHP_ (an unofficial PHP port of Bower). Beware that this is still in | ||
an alpha state. If you're using BowerPHP, use ``bowerphp`` instead of | ||
``bower`` in the examples. | ||
|
||
Configuring Bower in your Project | ||
--------------------------------- | ||
|
||
Normally, Bower downloads everything into a ``bower_components/`` directory. In | ||
Symfony, only files in the ``web/`` directory are publicly accessible, so you | ||
need to configure Bower to download things there instead. To do that, just | ||
create a ``.bowerrc`` file with a new destination (like ``web/assets/vendor``): | ||
|
||
.. code-block:: json | ||
|
||
{ | ||
"directory": "web/assets/vendor/" | ||
} | ||
|
||
An Example: Installing Bootstrap | ||
-------------------------------- | ||
|
||
Believe it or not, but you're now ready to use Bower in your Symfony | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if this is necessary to say 👍 though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. emphasing the easiness of using tools is never bad imo :) |
||
application. As an example, you'll now install Bootstrap in your project and | ||
include it in your layout. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mention perhaps where can they source it from bower.io/search url? |
||
|
||
Installing the Dependency | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
To create a ``bower.json`` file, just run ``bower init``. Now you're ready to | ||
start adding things to your project. For example, to add Bootstrap_ to your | ||
``bower.json`` and download it, just run: | ||
|
||
.. code-block:: bash | ||
|
||
$ bower install --save bootstrap | ||
|
||
This will install Bootstrap and its dependencies in ``web/assets/vendor/`` (or | ||
whatever directory you configured in ``.bowerrc``). | ||
|
||
.. seealso:: | ||
|
||
For more details on how to use Bower, check out `Bower documentation`_. | ||
|
||
Including the Dependency in your Template | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Now that the dependencies are installed, you can include bootstrap in your | ||
template like normal CSS/JS: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: html+jinja | ||
|
||
{# app/Resources/views/layout.html.twig #} | ||
<!doctype html> | ||
<html> | ||
<head> | ||
{# ... #} | ||
|
||
<link rel="stylesheet" | ||
href="{{ asset('assets/vendor/bootstrap/dist/css/bootstrap.min.css') }}"> | ||
</head> | ||
|
||
{# ... #} | ||
</html> | ||
|
||
.. code-block:: html+php | ||
|
||
<!-- app/Resources/views/layout.html.php --> | ||
<!doctype html> | ||
<html> | ||
<head> | ||
{# ... #} | ||
|
||
<link rel="stylesheet" href="<?php echo $view['assets']->getUrl( | ||
'assets/vendor/bootstrap/dist/css/bootstrap.min.css' | ||
) ?>"> | ||
</head> | ||
|
||
{# ... #} | ||
</html> | ||
|
||
Great job! Your site is now using Bootstrap. You can now easily upgrade | ||
bootstrap to the latest version and manage other front-end dependencies too. | ||
|
||
.. _Bower: http://bower.io | ||
.. _`Node.js`: https://nodejs.org | ||
.. _BowerPHP: http://bowerphp.org/ | ||
.. _`Bower documentation`: http://bower.io/ | ||
.. _Bootstrap: http://getbootstrap.com/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Front-end | ||
========= | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
bower |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, see #5155 (comment)