Skip to content

Commit 9c07033

Browse files
committed
Proofing part of the new assetic chapter
1 parent 86528a6 commit 9c07033

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

book/templating.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ advantage of Symfony's template inheritance.
798798
and Javascript assets in Symfony. Symfony also packages another library,
799799
called assetic, which follows this philosophy but allows you to do much
800800
more interesting things with those assets. For more information on
801-
using assetic see :doc:`/cookbook/assetic/yuicompressor`.
801+
using assetic see :doc:`/cookbook/assetic/asset_management`.
802802

803803

804804
Start by adding two blocks to your base template that will hold your assets:

cookbook/assetic/asset_management.rst

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
How to Use Assetic for Asset Management
22
=======================================
33

4-
Assetic is an asset management library which is packaged with the standard
5-
Symfony2 distribution, it has a bundle to allow it to be easily used
6-
in Symfony2 directly from Twig or PHP templates. It works with assets and
7-
filters. The assets are files such as CSS, JavaScript and images files.
8-
There are various filters that can be applied to these files before they
9-
are served to the browser. This allows a separation between the asset files
10-
stored in the application and the files actually presented to the user.
11-
Without using Assetic or another asset manager you are just directly serving
12-
up the files that are stored in the application:
4+
Assetic is a powerful asset management library which is packaged with the
5+
Symfony2 Standard Edition and can be easily used in Symfony2 directly from
6+
Twig or PHP templates.
7+
8+
Assetic combines two major ideas: assets and filters. The assets are files
9+
such as CSS, JavaScript and images files. The filters are things that can
10+
be applied to these files before they are served to the browser. This allows
11+
a separation between the asset files stored in the application and the files
12+
actually presented to the user.
13+
14+
Without Assetic, you just serve the files that are stored in the application
15+
directly:
1316

1417
.. configuration-block::
1518

@@ -22,29 +25,45 @@ up the files that are stored in the application:
2225
<script src="<?php echo $view['assets']->getUrl('js/script.js') ?>"
2326
type="text/javascript" />
2427
28+
But *with* Assetic, you can manipulate these assets however you want (or
29+
load them from anywhere) before serving them. These means you can:
30+
31+
* Minify and combine all of your CSS and JS files
32+
33+
* Run all (or just some) of your CSS or JS files through some sort of compiler,
34+
such as LESS, SASS or CoffeeScript
35+
36+
* Run image optimizations on your images
37+
2538
Assets
2639
------
2740
2841
Using Assetic provides many advantages over directly serving the files.
2942
The files do not need to be stored where they are served from and can be
30-
drawn from various sources such as within a bundle:
43+
drawn from various sources such as from within a bundle:
3144
3245
.. configuration-block::
3346
3447
.. code-block:: html+jinja
3548
3649
{% javascripts '@AcmeFooBundle/Resources/public/js/*'
3750
%}
38-
<script src="{{ asset_url }}"></script>
51+
<script type="text/javascript" src="{{ asset_url }}"></script>
3952
{% endjavascripts %}
4053
4154
.. code-block:: html+php
4255

4356
<?php foreach ($view['assetic']->javascripts(
4457
array('@AcmeFooBundle/Resources/public/js/*')) as $url): ?>
45-
<script src="<?php echo $view->escape($url) ?>"></script>
58+
<script type="text/javascript" src="<?php echo $view->escape($url) ?>"></script>
4659
<?php endforeach; ?>
4760
61+
In this example, all of the files in the ``Resources/public/js/`` directory
62+
of the ``AcmeFooBundle`` will be loaded and served from a different location.
63+
The actual rendered tag might simply look like:
64+
65+
<script src="/js/abcd123.js"></script>
66+
4867
You can also combine several files into one. This helps to reduce the number
4968
of HTTP requests which is good for front end performance, as most browsers
5069
will only process a limited number at a time slowing down page load times.
@@ -73,7 +92,6 @@ but still serve them as a single file:
7392
<script src="<?php echo $view->escape($url) ?>"></script>
7493
<?php endforeach; ?>
7594
76-
7795
This does not only apply to your own files you can also use Assetic to
7896
combine third party assets, such as jQuery with your own into a single file:
7997

cookbook/index.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Cookbook
99

1010
routing/scheme
1111
routing/slash_in_parameter
12-
12+
13+
assetic/asset_management
1314
assetic/yuicompressor
14-
templating/PHP
1515

1616
doctrine/doctrine_fixtures
1717
doctrine/mongodb
@@ -58,6 +58,8 @@ Cookbook
5858

5959
cache/varnish
6060

61+
templating/PHP
62+
6163
tools/autoloader
6264
tools/finder
6365
console

cookbook/map.rst.inc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
* :doc:`/cookbook/routing/scheme`
99
* :doc:`/cookbook/routing/slash_in_parameter`
1010

11-
* **Templating and Assets**
11+
* **Handling JavaScript and CSS Assets**
1212

13+
* :doc:`/cookbook/assetic/asset_management`
1314
* :doc:`/cookbook/assetic/yuicompressor`
14-
* :doc:`/cookbook/templating/PHP`
1515

1616
* **Database Interaction (Doctrine)**
1717

@@ -75,6 +75,10 @@
7575

7676
* :doc:`/cookbook/cache/varnish`
7777

78+
* **Templating**
79+
80+
* :doc:`/cookbook/templating/PHP`
81+
7882
* **Tools, Logging and Internals**
7983

8084
* :doc:`/cookbook/tools/autoloader`

0 commit comments

Comments
 (0)