8000 Merge pull request #1095 from kbond/hinclude · symfony/symfony-docs@d04b06d · GitHub
[go: up one dir, main page]

Skip to content

Commit d04b06d

Browse files
committed
Merge pull request #1095 from kbond/hinclude
[book][templating] added hinclude.js docs
2 parents c3e2cbc + c8d31a8 commit d04b06d

File tree

1 file changed

+63
-8
lines changed

1 file changed

+63
-8
lines changed

book/templating.rst

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,16 @@ Throughout this chapter, template examples will be shown in both Twig and PHP.
122122
not program logic. The more you use Twig, the more you'll appreciate
123123
and benefit from this distinction. And of course, you'll be loved by
124124
web designers everywhere.
125-
125+
126126
Twig can also do things that PHP can't, such as true template inheritance
127127
(Twig templates compile down to PHP classes that inherit from each other),
128128
whitespace control, sandboxing, and the inclusion of custom functions
129129
and filters that only affect templates. Twig contains little features
130130
that make writing templates easier and more concise. Take the following
131131
example, which combines a loop with a logical ``if`` statement:
132-
132+
133133
.. code-block:: html+jinja
134-
134+
135135
<ul>
136136
{% for user in users %}
137137
<li>{{ user.username }}</li>
@@ -634,6 +634,60 @@ Whenever you find that you need a variable or a piece of information that
634634
you don't have access to in a template, consider rendering a controller.
635635
Controllers are fast to execute and promote good code organization and reuse.
636636

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+
637691
.. index::
638692
single: Templating; Linking to pages
639693

@@ -806,7 +860,7 @@ advantage of Symfony's template inheritance.
806860
This section will teach you the philosophy behind including stylesheet
807861
and Javascript assets in Symfony. Symfony also packages another library,
808862
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
810864
using Assetic see :doc:`/cookbook/assetic/asset_management`.
811865

812866

@@ -847,13 +901,13 @@ page. From inside that contact page's template, do the following:
847901

848902
{% block stylesheets %}
849903
{{ parent() }}
850-
904+
851905
<link href="{{ asset('/css/contact.css') }}" type="text/css" rel="stylesheet" />
852906
{% endblock %}
853-
907+
854908
{# ... #}
855909

856-
In the child template, you simply override the ``stylesheets`` block and
910+
In the child template, you simply override the ``stylesheets`` block and
857911
put your new stylesheet tag inside of that block. Of course, since you want
858912
to add to the parent block's content (and not actually *replace* it), you
859913
should use the ``parent()`` Twig function to include everything from the ``stylesheets``
@@ -1274,7 +1328,7 @@ pattern is to do the following:
12741328
public function indexAction()
12751329
{
12761330
$format = $this->getRequest()->getRequestFormat();
1277-
1331+
12781332
return $this->render('AcmeBlogBundle:Blog:index.'.$format.'.twig');
12791333
}
12801334
@@ -1342,3 +1396,4 @@ Learn more from the Cookbook
13421396
.. _`tags`: http://twig.sensiolabs.org/doc/tags/index.html
13431397
.. _`filters`: http://twig.sensiolabs.org/doc/filters/index.html
13441398
.. _`add your own extensions`: http://twig.sensiolabs.org/doc/extensions.html
1399+
.. _`hinclude.js`: http://mnot.github.com/hinclude/

0 commit comments

Comments
 (0)
0