Skip to content

Commit 2e649b3

Browse files
committed
Merge pull request #3230 from peterkokot/patch-assetic-image
Image assetic management
2 parents 1a425cc + b5ca005 commit 2e649b3

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

cookbook/assetic/asset_management.rst

+29-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ Using Assetic provides many advantages over directly serving the files.
4343
The files do not need to be stored where they are served from and can be
4444
drawn from various sources such as from within a bundle.
4545

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

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

132+
.. _cookbook-assetic-including-image:
133+
134+
Including images
135+
~~~~~~~~~~~~~~~~
136+
137+
To include an image you can use the ``image`` tag.
138+
139+
.. configuration-block::
140+
141+
.. code-block:: html+jinja
142+
143+
{% image '@AcmeFooBundle/Resources/public/images/example.jpg' %}
144+
<img src="{{ asset_url }}" alt="Example" />
145+
{% endimage %}
146+
147+
.. code-block:: html+php
148+
149+
<?php foreach ($view['assetic']->image(
150+
array('@AcmeFooBundle/Resources/public/images/example.jpg')
151+
) as $url): ?>
152+
<img src="<?php echo $view->escape($url) ?>" alt="Example" />
153+
<?php endforeach; ?>
154+
155+
You can also use Assetic for image optimization. More information in
156+
:doc:`/cookbook/assetic/jpeg_optimize`.
157+
131158
.. _cookbook-assetic-cssrewrite:
132159

133160
Fixing CSS Paths with the ``cssrewrite`` Filter

cookbook/assetic/jpeg_optimize.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ It can now be used from a template:
6464

6565
.. code-block:: html+php
6666

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

0 commit comments

Comments
 (0)