Skip to content
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

move assets options from templating to assets section and add base_path documentation #6172

Merged
merged 7 commits into from
Feb 21, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions book/templating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ being used and generating the correct paths accordingly.
Additionally, if you use the ``asset`` function, Symfony can automatically
append a query string to your asset, in order to guarantee that updated static
assets won't be cached when deployed. For example, ``/images/logo.png`` might
look like ``/images/logo.png?v2``. For more information, see the :ref:`ref-framework-assets-version`
look like ``/images/logo.png?v2``. For more information, see the :ref:`reference-framework-assets-version`
configuration option.

.. _`book-templating-version-by-asset`:
Expand All @@ -1088,7 +1088,7 @@ if you are using Twig (or the fourth argument if you are using PHP) to the desir
) ?>" alt="Symfony!" />

If you don't give a version or pass ``null``, the default package version
(from :ref:`ref-framework-assets-version`) will be used. If you pass ``false``,
(from :ref:`reference-framework-assets-version`) will be used. If you pass ``false``,
versioned URL will be deactivated for this asset.

If you need absolute URLs for assets, you can set the ``absolute`` argument
Expand Down
2 changes: 1 addition & 1 deletion cookbook/assetic/asset_management.rst
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ done from the template and is relative to the public document root:
Symfony also contains a method for cache *busting*, where the final URL
generated by Assetic contains a query parameter that can be incremented
via configuration on each deployment. For more information, see the
:ref:`ref-framework-assets-version` configuration option.
:ref:`reference-framework-assets-version` configuration option.

.. _cookbook-assetic-dumping:

Expand Down
2 changes: 1 addition & 1 deletion reference/configuration/assetic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Full Default Configuration
some_filter: []
workers:
# see https://github.com/symfony/AsseticBundle/pull/119
# Cache can also be busted via the framework.templating.assets_version
# Cache can also be busted via the framework.assets.version
# setting - see the "framework" configuration section
cache_busting:
enabled: false
Expand Down
62 changes: 37 additions & 25 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ Configuration
* `gc_probability`_
* `gc_maxlifetime`_
* `save_path`_
* `assets`_
* `version`_
* `version_format`_
* `templating`_
* `assets_version`_
* `assets_version_format`_
* `hinclude_default_template`_
* :ref:`form <reference-templating-form>`
* `resources`_
Expand Down Expand Up @@ -850,14 +851,13 @@ setting the value to ``null``:
),
));

templating
~~~~~~~~~~
assets
~~~~~~

.. _reference-framework-assets-version:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not remove this anchor (there may be external links to it).

.. _ref-framework-assets-version:

assets_version
..............
version
.......

**type**: ``string``

Expand All @@ -879,7 +879,7 @@ For example, suppose you have the following:
<img src="<?php echo $view['assets']->getUrl('images/logo.png') ?>" alt="Symfony!" />

By default, this will render a path to your image such as ``/images/logo.png``.
Now, activate the ``assets_version`` option:
Now, activate the ``version`` option:

.. configuration-block::

Expand All @@ -888,7 +888,10 @@ Now, activate the ``assets_version`` option:
# app/config/config.yml
framework:
# ...
templating: { engines: ['twig'], assets_version: v2 }
assets:
version: 'v2'
templating:
engines: ['twig']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can omit the templating node entirely here (same for the other formats).


.. code-block:: xml

Expand All @@ -900,7 +903,8 @@ Now, activate the ``assets_version`` option:
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:templating assets-version="v2">
<framework:assets version="v2">
<framework:templating>
<!-- ... -->
<framework:engine>twig</framework:engine>
</framework:templating>
Expand All @@ -911,40 +915,42 @@ Now, activate the ``assets_version`` option:
// app/config/config.php
$container->loadFromExtension('framework', array(
// ...
'templating' => array(
'engines' => array('twig'),
'assets_version' => 'v2',
'assets' => array(
'version' => 'v2',
),
'templating' => array(
'engines' => array('twig'),
),
));

Now, the same asset will be rendered as ``/images/logo.png?v2`` If you use
this feature, you **must** manually increment the ``assets_version`` value
this feature, you **must** manually increment the ``version`` value
before each deployment so that the query parameters change.

It's also possible to set the version value on an asset-by-asset basis (instead
of using the global version - e.g. ``v2`` - set here). See
:ref:`Versioning by Asset <book-templating-version-by-asset>` for details.

You can also control how the query string works via the `assets_version_format`_
You can also control how the query string works via the `version_format`_
option.

.. tip::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old label should be kept.


As with all settings, you can use a parameter as value for the
``assets_version``. This makes it easier to increment the cache on each
``version``. This makes it easier to increment the cache on each
deployment.

.. _reference-templating-version-format:
.. _reference-assets-version-format:

assets_version_format
.....................
version_format
..............

**type**: ``string`` **default**: ``%%s?%%s``

This specifies a :phpfunction:`sprintf` pattern that will be used with the
`assets_version`_ option to construct an asset's path. By default, the pattern
`version`_ option to construct an asset's path. By default, the pattern
adds the asset's version as a query string. For example, if
``assets_version_format`` is set to ``%%s?version=%%s`` and ``assets_version``
``version_format`` is set to ``%%s?version=%%s`` and ``version``
is set to ``5``, the asset's path would be ``/images/logo.png?version=5``.

.. note::
Expand All @@ -957,7 +963,7 @@ is set to ``5``, the asset's path would be ``/images/logo.png?version=5``.

Some CDN's do not support cache-busting via query strings, so injecting
the version into the actual file path is necessary. Thankfully,
``assets_version_format`` is not limited to producing versioned query
``version_format`` is not limited to producing versioned query
strings.

The pattern receives the asset's original path and version as its first
Expand All @@ -973,6 +979,9 @@ is set to ``5``, the asset's path would be ``/images/logo.png?version=5``.
any URL rewriting. The latter option is useful if you would like older
asset versions to remain accessible at their original URL.

templating
~~~~~~~~~~

hinclude_default_template
.........................

Expand Down Expand Up @@ -1277,7 +1286,7 @@ Each package can configure the following options:

* :ref:`base_urls <reference-templating-base-urls>`
* :ref:`version <reference-framework-assets-version>`
* :ref:`version_format <reference-templating-version-format>`
* :ref:`version_format <reference-assets-version-format>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The complete block about packages should be moved to the assets node too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the same applies to the base url options


translator
~~~~~~~~~~
Expand Down Expand Up @@ -1589,10 +1598,13 @@ Full Default Configuration
serializer:
enabled: false

# assets configuration
assets:
version: ~
version_format: '%%s?%%s'

# templating configuration
templating:
assets_version: ~
assets_version_format: '%%s?%%s'
hinclude_default_template: ~
form:
resources:
Expand Down
2 changes: 1 addition & 1 deletion reference/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ asset

Returns a public path to ``path``, which takes into account the base path
set for the package and the URL path. More information in
:ref:`book-templating-assets`. For asset versioning, see :ref:`ref-framework-assets-version`.
:ref:`book-templating-assets`. For asset versioning, see :ref:`reference-framework-assets-version`.

assets_version
~~~~~~~~~~~~~~
Expand Down