@@ -122,16 +122,16 @@ Throughout this chapter, template examples will be shown in both Twig and PHP.
122
122
not program logic. The more you use Twig, the more you'll appreciate
123
123
and benefit from this distinction. And of course, you'll be loved by
124
124
web designers everywhere.
125
-
125
+
126
126
Twig can also do things that PHP can't, such as true template inheritance
127
127
(Twig templates compile down to PHP classes that inherit from each other),
128
128
whitespace control, sandboxing, and the inclusion of custom functions
129
129
and filters that only affect templates. Twig contains little features
130
130
that make writing templates easier and more concise. Take the following
131
131
example, which combines a loop with a logical ``if `` statement:
132
-
132
+
133
133
.. code-block :: html+jinja
134
-
134
+
135
135
<ul>
136
136
{% for user in users %}
137
137
<li>{{ user.username }}</li>
@@ -634,6 +634,60 @@ Whenever you find that you need a variable or a piece of information that
634
634
you don't have access to in a template, consider rendering a controller.
635
635
Controllers are fast to execute and promote good code organization and reuse.
636
636
637
+ Asyncronous Content with hinclude.js
638
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
639
+
640
+ .. versionadded :: 2.1
641
+ hinclude.js support was added in Symfony 2.1
642
+
643
+ Controllers can be embedded asyncronous using the hinclude.js _ javascript library.
644
+ As the embedded content comes from another page (or controller for that matter),
645
+ Symfony2 uses the standard ``render `` helper to configure ``hinclude `` tags:
646
+
647
+ .. configuration-block ::
648
+
649
+ .. code-block :: jinja
650
+
651
+ {% render '...:news' with {}, {'standalone': 'js'} %}
652
+
653
+ .. code-block :: php
654
+
655
+ <?php echo $view['actions']->render('...:news', array(), array('standalone' => 'js')) ?>
656
+
657
+ .. note ::
658
+
659
+ hinclude.js _ needs to be included in your page to work.
660
+
661
+ Default content (while loading or if javascript is disabled) can be set globally
662
+ in your application configuration:
663
+
664
+ .. configuration-block ::
665
+
666
+ .. code-block :: yaml
667
+
668
+ # app/config/config.yml
669
+ framework :
670
+ # ...
671
+ templating :
672
+ hinclude_default_template : AcmeDemoBundle::hinclude.html.twig
673
+
674
+ .. code-block :: xml
675
+
676
+ <!-- app/config/config.xml -->
677
+ <framework : config >
678
+ <framework : templating hinclude-default-template =" AcmeDemoBundle::hinclude.html.twig" />
679
+ </framework : config >
680
+
681
+ .. code-block :: php
682
+
683
+ // app/config/config.php
684
+ $container->loadFromExtension('framework', array(
685
+ // ...
686
+ 'templating' => array(
687
+ 'hinclude_default_template' => array('AcmeDemoBundle::hinclude.html.twig'),
688
+ ),
689
+ ));
690
+
637
691
.. index ::
638
692
single: Templating; Linking to pages
639
693
@@ -806,7 +860,7 @@ advantage of Symfony's template inheritance.
806
860
This section will teach you the philosophy behind including stylesheet
807
861
and Javascript assets in Symfony. Symfony also packages another library,
808
862
called Assetic, which follows this philosophy but allows you to do much
809
- more interesting things with those assets. For more information on
863
+ more interesting things with those assets. For more information on
810
864
using Assetic see :doc: `/cookbook/assetic/asset_management `.
811
865
812
866
@@ -847,13 +901,13 @@ page. From inside that contact page's template, do the following:
847
901
848
902
{% block stylesheets %}
849
903
{{ parent() }}
850
-
904
+
851
905
<link href="{{ asset('/css/contact.css') }}" type="text/css" rel="stylesheet" />
852
906
{% endblock %}
853
-
907
+
854
908
{# ... #}
855
909
856
- In the child template, you simply override the ``stylesheets `` block and
910
+ In the child template, you simply override the ``stylesheets `` block and
857
911
put your new stylesheet tag inside of that block. Of course, since you want
858
912
to add to the parent block's content (and not actually *replace * it), you
859
913
should use the ``parent() `` Twig function to include everything from the ``stylesheets ``
@@ -1274,7 +1328,7 @@ pattern is to do the following:
1274
1328
public function indexAction()
1275
1329
{
1276
1330
$format = $this->getRequest()->getRequestFormat();
1277
-
1331
+
1278
1332
return $this->render('AcmeBlogBundle:Blog:index.'.$format.'.twig');
1279
1333
}
1280
1334
@@ -1342,3 +1396,4 @@ Learn more from the Cookbook
1342
1396
.. _`tags` : http://twig.sensiolabs.org/doc/tags/index.html
1343
1397
.. _`filters` : http://twig.sensiolabs.org/doc/filters/index.html
1344
1398
.. _`add your own extensions` : http://twig.sensiolabs.org/doc/extensions.html
1399
+ .. _`hinclude.js` : http://mnot.github.com/hinclude/