Browse Source

Moved "row templates" section into separate recipe, ref #1542
Added link to new recipe from the main index.rst file

Christian Morgan 11 years ago
parent
commit
158d3f5a84

+ 1 - 0
Resources/doc/index.rst

@@ -45,6 +45,7 @@ Reference Guide
    reference/troubleshooting
    reference/recipe_file_uploads
    reference/recipe_image_previews
+   reference/recipe_row_templates
 
 Overview
 --------

+ 83 - 0
Resources/doc/reference/recipe_row_templates.rst

@@ -0,0 +1,83 @@
+Row templates
+=============
+
+From Sonata-2.2 it is possible to define a template per row for the list action. 
+The default template is a standard table but there are circumstances where this
+type of layout might not be suitable. By defining a custom template for the row, 
+you can tweak the layout into something like this:
+
+.. figure:: ./../images/sonata_inline_row.png
+   :align: center
+   :alt: Inline Row from the SonataNewsBundle
+   :width: 700px
+
+
+The recipe
+----------
+
+Configure your Admin service
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The configuration takes place in the DIC by calling the ``setTemplates`` method. 
+Two template keys need to be set:
+
+- ``inner_list_row``: The template for the row, which you will customize. Often
+  you will want this to extend ``SonataAdminBundle:CRUD:base_list_flat_inner_row.html.twig``
+- ``base_list_field``: The base template for the cell, the default of
+  ``SonataAdminBundle:CRUD:base_list_flat_field.html.twig`` is suitable for most 
+  cases but it can be customized if required.
+
+.. code-block:: xml
+
+    <service id="sonata.admin.comment" class="%sonata.admin.comment.class%">
+        <tag name="sonata.admin" manager_type="orm" group="sonata_blog" label="comments" 
+            label_catalogue="%sonata.admin.comment.translation_domain%" 
+            label_translator_strategy="sonata.admin.label.strategy.underscore" />
+        <argument />
+        <argument>%sonata.admin.comment.entity%</argument>
+        <argument>%sonata.admin.comment.controller%</argument>
+
+        <call method="setTemplates">
+            <argument type="collection">
+                <argument key="inner_list_row">
+                    YourNSYourBundle:Admin:inner_row_comment.html.twig
+                </argument>
+                <argument key="base_list_field">
+                    SonataAdminBundle:CRUD:base_list_flat_field.html.twig
+                </argument>
+            </argument>
+        </call>
+    </service>
+
+
+Create your customized template
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Once the templates are defined, create the template to render the row:
+
+.. code-block:: jinja
+
+    {# This file is YourNSYourBundle:Admin:inner_row_comment.html.twig #}
+
+    {# Extend the default template, which provides batch and action cells #}
+    {#     as well as the valid colspan computation #}
+    {% extends 'SonataAdminBundle:CRUD:base_list_flat_inner_row.html.twig' %}
+
+    {% block row %}
+
+        {# you can use fields define in the the Admin class #}
+        {{ object|render_list_element(admin.list['name']) }} -
+        {{ object|render_list_element(admin.list['url']) }} -
+        {{ object|render_list_element(admin.list['email']) }} <br />
+
+        <small>
+            {# or you can use the object variable to render a property #}
+            {{ object.message }}
+        </small>
+
+    {% endblock %}
+
+While this feature is nice to generate a rich list, it is also very easy to 
+break the layout and admin features such as batch and object actions. It is
+best to familiarise yourself with the default templates and extend them where
+possible, only changing what you need to customize.

+ 3 - 57
Resources/doc/reference/templates.rst

@@ -98,60 +98,6 @@ You can easily extend the provided templates in your own template and customize
 Row Template
 ------------
 
-From 2.2, it is possible to define a template per row for the list action, the default one is a standard table. However,
-depends on the data the table layout might not be suitable. So by defining a custom template for the row, it will be
-possible to tweak the layout as:
-
-.. figure:: ./../images/sonata_inline_row.png
-   :align: center
-   :alt: Inline Row from the SonataNewsBundle
-   :width: 700px
-
-
-How to use it
-~~~~~~~~~~~~~
-
-The configuration takes place in the DIC by calling the ``setTemplates`` method. Two template keys need to be set:
-
-- ``inner_list_row`` : The template for the row, this one need to be customized
-- ``base_list_field`` : The base template for the cell, the ``SonataAdminBundle:CRUD:base_list_flat_field.html.twig``
-is suitable for most cases, however advance use might want to change it.
-
-.. code-block:: xml
-
-    <service id="sonata.news.admin.comment" class="%sonata.news.admin.comment.class%">
-        <tag name="sonata.admin" manager_type="orm" group="sonata_blog" label="comments" label_catalogue="%sonata.news.admin.comment.translation_domain%" label_translator_strategy="sonata.admin.label.strategy.underscore" />
-        <argument />
-        <argument>%sonata.news.admin.comment.entity%</argument>
-        <argument>%sonata.news.admin.comment.controller%</argument>
-
-        <call method="setTemplates">
-            <argument type="collection">
-                <argument key="inner_list_row">SonataNewsBundle:Admin:inner_row_comment.html.twig</argument>
-                <argument key="base_list_field">SonataAdminBundle:CRUD:base_list_flat_field.html.twig</argument>
-            </argument>
-        </call>
-    </service>
-
-Once the template is set, edit the template ``SonataNewsBundle:Admin:inner_row_comment.html.twig``
-
-.. code-block:: jinja
-
-    {# The default template which provides batch and action cells, with the valid colspan computation #}
-    {% extends 'SonataAdminBundle:CRUD:base_list_flat_inner_row.html.twig' %}
-
-    {% block row %}
-
-        {# use field define in the the Admin class #}
-        {{ object|render_list_element(admin.list['name']) }} -
-        {{ object|render_list_element(admin.list['url']) }} -
-        {{ object|render_list_element(admin.list['email']) }} <br />
-
-        <small>
-            {# or you can use the object variable to render a property #}
-            {{ object.message }}
-        </small>
-
-    {% endblock %}
-
-While this feature is nice to generate rich list, it is also very easy to break the layout and admin features: batch and actions.
+It is possible to completely change how each row of results is rendered in the 
+list view. For more information about this, see the :doc:`recipe_row_templates` 
+cookbook entry.