Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #179 from WouterJ/more_formats
Browse files Browse the repository at this point in the history
Added more formats (mostly templating)
  • Loading branch information
dbu committed Jul 12, 2013
2 parents aa4dc8e + 451b389 commit 60fd16f
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 38 deletions.
98 changes: 86 additions & 12 deletions bundles/block/cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ CmfBlockBundle and the SonataBlockBundle:
<?xml version="1.0" charset="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services">
<config xmlns="http://example.org/schema/dic/sonata_block">
<!-- use the service id of the cache adapter -->
<blocks id="symfony_cmf.block.action"
cache="symfony_cmf.block.cache.js_async"
/>
</config>
</container>
<config xmlns="http://sonata-project.org/schema/dic/block">
<!-- use the service id of the cache adapter -->
<blocks id="symfony_cmf.block.action"
cache="symfony_cmf.block.cache.js_async"
/>
</config>
</container>
.. code-block:: php
Expand Down Expand Up @@ -213,12 +213,25 @@ your Twig template when using cache:
* **use_cache**: use the configured cache for a block (*default*: true)
* **extra_cache_keys**: expects an array with extra cache keys (*default*: empty array)

.. code-block:: jinja
.. configuration-block::

.. code-block:: jinja
{{ sonata_block_render({ 'name': 'rssBlock' }, {
use_cache: true,
extra_cache_keys: { 'extra_key': 'my_block' }
}) }}
.. code-block:: php+html

{{ sonata_block_render({ 'name': 'rssBlock' }, {
'use_cache': true,
'extra_cache_keys': { 'extra_key': 'my_block' }
}) }}
<?php echo $view['blocks']->render(array(
'name' => 'rssBlock',
), array(
'use_cache' => true,
'extra_cache_keys' => array(
'extra_key' => 'my_block'
),
)) ?>

When using the Esi, Ssi or Js cache adapters the settings passed here are remembered:

Expand Down Expand Up @@ -290,6 +303,38 @@ Configuration
servers:
- varnishadm -T 127.0.0.1:2000 {{ COMMAND }} "{{ EXPRESSION }}"
.. code-block:: xml
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services">
<config xmlns="http://cmf.symfony.com/schema/dic/block">
<caches>
<!-- token: a random one is generated by default -->
<varnish token="a unique security key">
<server>varnishadm -T 127.0.0.1:2000 {{ COMMAND }} "{{ EXPRESSION }}"</server>
</varnish>
</caches>
</config>
</container>
.. code-block:: php
// app/config/config.php
$container->loadFromExtension('cmf_block', array(
// ...
'caches' => array(
'varnish' => array(
'token' => 'a unique security key', // a random one is generated by default
'servers' => array(
'varnishadm -T 127.0.0.1:2000 {{ COMMAND }} "{{ EXPRESSION }}"',
),
),
),
));
SSI
~~~

Expand All @@ -309,6 +354,35 @@ Configuration
ssi:
token: a unique security key # a random one is generated by default
.. code-block:: xml
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services">
<config xmlns="http://cmf.symfony.com/schema/dic/block">
<caches>
<!-- token: a random one is generated by default -->
<ssi
token="a unique security key"
/>
</caches>
</config>
</container>
.. code-block:: php
// app/config/config.php
$container->loadFromExtension('cmf_block', array(
// ...
'caches' => array(
'ssi' => array(
'token' => 'a unique security key', // a random one is generated by default
),
),
));
Javascript
~~~~~~~~~~

Expand Down
58 changes: 45 additions & 13 deletions bundles/block/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ specific settings for one of the block classes.
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services">
<config xmlns="http://example.org/schema/dic/sonata_block">
<config xmlns="http://sonata-project.com/schema/dic/block">
<blocks id="acme_main.block.rss">
<settings id="maxItems">3</settings>
</blocks>
Expand Down Expand Up @@ -233,12 +233,21 @@ Settings can be altered on multiple places afterwards, it cascades like this:

Example of how settings can be specified through a template helper:

.. code-block:: jinja
.. configuration-block::

.. code-block:: jinja
{{ sonata_block_render({'name': 'rssBlock'}, {
'title': 'Symfony2 CMF news',
'url': 'http://cmf.symfony.com/news.rss'
}) }}
{{ sonata_block_render({'name': 'rssBlock'}, {
'title': 'Symfony2 CMF news',
'url': 'http://cmf.symfony.com/news.rss'
}) }}
.. code-block:: php+html

<?php $view['blocks']->render(array('name' => 'rssBlock'), array(
'title' => 'Symfony2 CMF news',
'url' => 'http://cmf.symfony.com/news.rss',
)) ?>

Form Configuration
~~~~~~~~~~~~~~~~~~
Expand All @@ -261,10 +270,17 @@ javascript and stylesheet assets. Use the twig helpers
``sonata_block_include_javascripts`` and ``sonata_block_include_stylesheets``
to render them:

.. code-block:: jinja
.. configuration-block::

.. code-block:: jinja
{{ sonata_block_include_javascripts() }}
{{ sonata_block_include_stylesheets() }}
{{ sonata_block_include_javascripts() }}
{{ sonata_block_include_stylesheets() }}
.. code-block:: php+html

<?php $view['blocks']->includeJavaScripts() ?>
<?php $view['blocks']->includeStylesheets() ?>

.. note::

Expand All @@ -285,17 +301,33 @@ Block rendering
To render the example from the :ref:`bundle-block-document` section, just add
the following code to your Twig template:

.. code-block:: jinja
.. configuration-block::

{{ sonata_block_render({'name': '/cms/content/blocks/sidebarBlock'}) }}
.. code-block:: jinja
{{ sonata_block_render({'name': '/cms/content/blocks/sidebarBlock'}) }}
.. code-block:: php+html

<?php echo $view['blocks']->render(array(
'name' => '/cms/content/blocks/sidebarBlock',
)) ?>

In this example we specify an absolute path, however, if the block is a child
of a content document, then you can simply specify the **name** of the block
as follows:

.. code-block:: jinja
.. configuration-block::

.. code-block:: jinja
{{ sonata_block_render({'name': 'sidebarBlock'}) }}
.. code-block:: php+html

{{ sonata_block_render({'name': 'sidebarBlock'}) }}
<?php echo $view['blocks']->render(array(
'name' => 'sidebarBlock',
)) ?>

This will make the BlockBundle render the specified block on every page that
has a child block document named ``sidebarBlock``. Of course, the actual page
Expand Down
49 changes: 44 additions & 5 deletions bundles/block/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ types of blocks in the same slideshow.
of your site and hook it on the slideshows. (See also below).


Create your first slideshow
Create your first Slideshow
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Creating a slideshow consists of creating the container ``SlideshowBlock`` and
Expand Down Expand Up @@ -237,11 +237,19 @@ Rendering your slideshow is as easy as just rendering the according block
in your template. If your ``contentDocument`` has a field ``slideshow`` that
contains a ``SlideshowBlock`` object, you can simply render it with:

.. code-block:: jinja
.. configuration-block::

.. code-block:: jinja
{{ sonata_block_render({
'name': 'slideshow'
}) }}
{{ sonata_block_render({
'name': 'slideshow'
}) }}
.. code-block:: php+html

<?php echo $view['blocks']->render(array(
'name' => 'slideshow',
)) ?>


Make the slideshow work in the frontend
Expand Down Expand Up @@ -274,6 +282,37 @@ following line to your sonata admin configuration:
items:
- cmf_block.slideshow_admin
.. code-block:: xml
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services">
<config xmlns="http://example.org/schema/dic/sonata_admin">
<dashboard>
<group id="blocks"
label="Blocks">
<item>cmf_block.slideshow_admin</item>
</group>
</dashboard>
</config>
</container>
.. code-block:: php
$container->loadFromExtension('sonata_admin', array(
'dashboard' => array(
'groups' => array(
'blocks' => array(
'label' => 'Blocks',
'items' => array(
'cmf_block.slideshow_admin',
),
),
),
),
));
However, you can also embed the slideshow administration directly into
other admin classes using the ``sonata_type_admin`` form type. The admin
service to use in that case is ``cmf_block.slideshow_admin``.
Expand Down
Loading

0 comments on commit 60fd16f

Please sign in to comment.