Skip to content

Commit

Permalink
Merge branch '2.3' into 2.5
Browse files Browse the repository at this point in the history
* 2.3:
  [#4928] Backporting change after merging into 2.5 (since 2.3 is a little different)
  Fixed a minor RST syntax issue
  Added a reference about including JS and CSS files in PHP templates
  Removed the Stable API chapter from the Symfony book

Conflicts:
	book/stable_api.rst
	components/debug/introduction.rst
  • Loading branch information
weaverryan committed Feb 1, 2015
2 parents 008c4de + 0afc689 commit 52e21f3
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 82 deletions.
1 change: 0 additions & 1 deletion book/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ The Book
service_container
performance
internals
stable_api

.. include:: /book/map.rst.inc
1 change: 0 additions & 1 deletion book/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
* :doc:`/book/service_container`
* :doc:`/book/performance`
* :doc:`/book/internals`
* :doc:`/book/stable_api`
56 changes: 0 additions & 56 deletions book/stable_api.rst

This file was deleted.

81 changes: 57 additions & 24 deletions book/templating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1091,43 +1091,76 @@ one called ``stylesheets`` inside the ``head`` tag and another called ``javascri
just above the closing ``body`` tag. These blocks will contain all of the
stylesheets and JavaScripts that you'll need throughout your site:

.. code-block:: html+jinja
.. configuration-block::

{# app/Resources/views/base.html.twig #}
<html>
<head>
{# ... #}
.. code-block:: html+jinja

{% block stylesheets %}
<link href="{{ asset('css/main.css') }}" rel="stylesheet" />
{% endblock %}
</head>
<body>
{# ... #}
{# app/Resources/views/base.html.twig #}
<html>
<head>
{# ... #}

{% block javascripts %}
<script src="{{ asset('js/main.js') }}"></script>
{% endblock %}
</body>
</html>
{% block stylesheets %}
<link href="{{ asset('css/main.css') }}" rel="stylesheet" />
{% endblock %}
</head>
<body>
{# ... #}

{% block javascripts %}
<script src="{{ asset('js/main.js') }}"></script>
{% endblock %}
</body>
</html>

.. code-block:: php
// app/Resources/views/base.html.php
<html>
<head>
<?php ... ?>
<?php $view['slots']->start('stylesheets') ?>
<link href="<?php echo $view['assets']->getUrl('css/main.css') ?>" rel="stylesheet" />
<?php $view['slots']->stop() ?>
</head>
<body>
<?php ... ?>
<?php $view['slots']->start('javascripts') ?>
<script src="<?php echo $view['assets']->getUrl('js/main.js') ?>"></script>
<?php $view['slots']->stop() ?>
</body>
</html>
That's easy enough! But what if you need to include an extra stylesheet or
JavaScript from a child template? For example, suppose you have a contact
page and you need to include a ``contact.css`` stylesheet *just* on that
page. From inside that contact page's template, do the following:

.. code-block:: html+jinja
.. configuration-block::

.. code-block:: html+jinja

{# app/Resources/views/Contact/contact.html.twig #}
{% extends 'base.html.twig' %}

{% block stylesheets %}
{{ parent() }}

<link href="{{ asset('css/contact.css') }}" rel="stylesheet" />
{% endblock %}

{# app/Resources/views/Contact/contact.html.twig #}
{% extends 'base.html.twig' %}
{# ... #}

{% block stylesheets %}
{{ parent() }}
.. code-block:: php
<link href="{{ asset('css/contact.css') }}" rel="stylesheet" />
{% endblock %}
// app/Resources/views/Contact/contact.html.twig
<?php $view->extend('base.html.php') ?>
{# ... #}
<?php $view['slots']->start('stylesheets') ?>
<link href="<?php echo $view['assets']->getUrl('css/contact.css') ?>" rel="stylesheet" />
<?php $view['slots']->stop() ?>
In the child template, you simply override the ``stylesheets`` block and
put your new stylesheet tag inside of that block. Of course, since you want
Expand Down
1 change: 1 addition & 0 deletions redirection_map
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/book/stable_api /contributing/code/bc
/cookbook/deployment-tools /cookbook/deployment/tools
/cookbook/doctrine/migrations /bundles/DoctrineFixturesBundle/index
/cookbook/doctrine/doctrine_fixtures /bundles/DoctrineFixturesBundle/index
Expand Down

0 comments on commit 52e21f3

Please sign in to comment.