8000 [2.7] Update Twig docs for asset features by wouterj · Pull Request #5574 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[2.7] Update Twig docs for asset features #5574

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

Merged
merged 2 commits into from
May 9, 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
Next Next commit
Updated Twig template to take into account asset() function changes
  • Loading branch information
javiereguiluz authored and wouterj committed May 5, 2016
commit bc18ff14a7be76f34bca59b8a92b3c89c4a79871
42 changes: 4 additions & 38 deletions book/templating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1067,46 +1067,12 @@ assets won't be loaded from cache after being deployed. For example, ``/images/l
look like ``/images/logo.png?v2``. For more information, see the :ref:`reference-framework-assets-version`
configuration option.

.. _`book-templating-version-by-asset`:
If you need absolute URLs for assets, use the ``absolute_url()`` Twig function
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to add a warning that this is not supported? Otherwise, people who use old links might get lost as the anchor wouldn't match anymore.

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 say yes

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean adding an admonition about this in the docs? I don't like that, it'll put completely unrelated text in the documentation (also, anyone linking to this currently wouldn't read the warning anyways)

Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I cannot remember anymore what I had in mind back then.

as follows:

If you need to set a version for a specific asset, you can set the ``version`` argument
if you are using Twig (or the fourth argument if you are using PHP) to the desired version:
.. code-block:: html+jinja

.. configuration-block::

.. code-block:: html+jinja

<img src="{{ asset('images/logo.png', version='3.0') }}" alt="Symfony!" />

.. code-block:: html+php

<img src="<?php echo $view['assets']->getUrl(
'images/logo.png',
null,
false,
'3.0'
) ?>" alt="Symfony!" />

If you don't give a version or pass ``null``, the default package version
(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 use the ``absolute_url`` function
if you are using Twig (or the third argument if you are using PHP) to ``true``:

.. configuration-block::

.. code-block:: html+jinja

<img src="{{ absolute_url(asset('images/logo.png')) }}" alt="Symfony!" />

.. code-block:: html+php

<img src="<?php echo $view['assets']->getUrl(
'images/logo.png',
null,
true
) ?>" alt="Symfony!" />
<img src="{{ absolute_url(asset('images/logo.png')) }}" alt="Symfony!" />

.. index::
single: Templating; Including stylesheets and JavaScripts
Expand Down
4 changes: 0 additions & 4 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1081,10 +1081,6 @@ Now, the same asset will be rendered as ``/images/logo.png?v2`` If you use
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 `version_format`_
option.

Expand Down
23 changes: 23 additions & 0 deletions reference/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ assets_version
Returns the current version of the package, more information in
:ref:`book-templating-assets`.

absolute_url
~~~~~~~~~~~~

.. code-block:: jinja

{{ absolute_url(asset(path, packageName)) }}

``path``
**type**: ``string``
``packageName``
**type**: ``string`` | ``null`` **default**: ``null``

Returns the absolute URL that corresponds to the given asset path and package.
More information in :ref:`book-templating-assets`. For configuring the base URLs,
:ref:`ref-framework-assets-base-urls`.

The absolute URLs generated with this function ignore the asset versioning.
Combine it with the ``assets_version()`` function to append the version number:

.. code-block:: jinja

{{ absolute_url(asset('logo.png')) ~ '?' ~ assets_version('images') }}

form
~~~~

Expand Down
0