Skip to content

Image assetic management #3230

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 1 commit into from
Nov 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
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
image tag for assetic management added and fixed a typo
  • Loading branch information
petk committed Nov 28, 2013
commit b5ca005d06ea907cd7c99baf5e689c21292f46fe
31 changes: 29 additions & 2 deletions cookbook/assetic/asset_management.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ Using Assetic provides many advantages over directly serving the files.
The files do not need to be stored where they are served from and can be
drawn from various sources such as from within a bundle.

You can use Assetic to process both :ref:`CSS stylesheets <cookbook-assetic-including-css>`
and :ref:`JavaScript files <cookbook-assetic-including-javascript>`. The philosophy
You can use Assetic to process :ref:`CSS stylesheets <cookbook-assetic-including-css>`,
:ref:`JavaScript files <cookbook-assetic-including-javascript>` and
:ref:`images <cookbook-assetic-including-image>`. The philosophy
behind adding either is basically the same, but with a slightly different syntax.

.. _cookbook-assetic-including-javascript:
Expand Down Expand Up @@ -128,6 +129,32 @@ the :ref:`cssrewrite <cookbook-assetic-cssrewrite>` filter.
that there is a known issue that causes the ``cssrewrite`` filter to fail
when using the ``@AcmeFooBundle`` syntax for CSS Stylesheets.

.. _cookbook-assetic-including-image:

Including images
~~~~~~~~~~~~~~~~

To include an image you can use the ``image`` tag.

.. configuration-block::

.. code-block:: html+jinja

{% image '@AcmeFooBundle/Resources/public/images/example.jpg' %}
Copy link
Contributor

Choose a reason for hiding this comment

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

this example does not match the one below right? here there is not a foreach

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now it's working. (I've used a wrong method name and made some syntax typos). Case is that assetic image method returns array and so foreach is needed here actually. More info here:
https://github.com/symfony/AsseticBundle/blob/master/Templating/AsseticHelper.php#L65
@cordoval Thanks for infos. Let me know if you find anything else that needs to be fixed here. Regards.

<img src="{{ asset_url }}" alt="Example" />
{% endimage %}

.. code-block:: html+php

<?php foreach ($view['assetic']->image(
array('@AcmeFooBundle/Resources/public/images/example.jpg')
) as $url): ?>
<img src="<?php echo $view->escape($url) ?>" alt="Example" />
<?php endforeach; ?>

You can also use Assetic for image optimization. More information in
:doc:`/cookbook/assetic/jpeg_optimize`.

.. _cookbook-assetic-cssrewrite:

Fixing CSS Paths with the ``cssrewrite`` Filter
Expand Down
2 changes: 1 addition & 1 deletion cookbook/assetic/jpeg_optimize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ It can now be used from a template:

.. code-block:: html+php

<?php foreach ($view['assetic']->images(
<?php foreach ($view['assetic']->image(
array('@AcmeFooBundle/Resources/public/images/example.jpg'),
array('jpegoptim')
) as $url): ?>
Expand Down