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

Commit 5c4a62c

Browse files
committed
Merge pull request #365 from symfony-cmf/remove-cookbook-block
removing blockbundle cookbook entry
2 parents 930db44 + aa40820 commit 5c4a62c

File tree

6 files changed

+112
-712
lines changed

6 files changed

+112
-712
lines changed

bundles/block/introduction.rst

Lines changed: 109 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ individually as follows:
3333

3434
.. code-block:: yaml
3535
36-
cmf_core:
36+
cmf_block:
3737
persistence:
3838
phpcr:
3939
block_basepath: /cms/content
@@ -43,7 +43,7 @@ individually as follows:
4343
<?xml version="1.0" charset="UTF-8" ?>
4444
<container xmlns="http://symfony.com/schema/dic/services">
4545
46-
<config xmlns="http://cmf.symfony.com/schema/dic/core">
46+
<config xmlns="http://cmf.symfony.com/schema/dic/block">
4747
<persistence>
4848
<phpcr
4949
block-basepath="/cms/block"
@@ -55,7 +55,7 @@ individually as follows:
5555
5656
.. code-block:: php
5757
58-
$container->loadFromExtension('cmf_core', array(
58+
$container->loadFromExtension('cmf_block', array(
5959
'persistence' => array(
6060
'phpcr' => array(
6161
'block_basepath' => '/cms/block',
@@ -328,6 +328,10 @@ time a block is rendered before the ``execute`` method is called.
328328
Block rendering
329329
---------------
330330

331+
Rendering is handled by the SonataBlockBundle ``sonata_block_render`` twig
332+
function. The block name is either an absolute PHPCR path or the name of the
333+
block relative to the ``cmfMainContent`` document.
334+
331335
To render the example from the :ref:`bundle-block-document` section, just add
332336
the following code to your Twig template:
333337

@@ -378,8 +382,107 @@ receives the block object (equivalent to a Request object) and a ``Response``
378382
object. The purpose of the ``execute`` method to set the content of the
379383
response object - typically by rendering a Twig template.
380384

381-
You can also :ref:`embed blocks in WYSIWYG content <tutorial-block-embed>`
382-
using the ``cmf_embed_blocks`` filter.
385+
.. _bundle-block-embed:
386+
387+
Embedding Blocks in WYSIWYG Content
388+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
389+
390+
The CmfBlockBundle provides a twig filter ``cmf_embed_blocks`` that
391+
looks through the content and looks for special tags to render blocks. To use
392+
the tag, you need to apply the ``cmf_embed_blocks`` filter to your output. If
393+
you can, render your blocks directly in the template. This feature is only a
394+
cheap solution for web editors to place blocks anywhere in their HTML content.
395+
A better solution to build composed pages is to build it from blocks (there
396+
might be a CMF bundle at some point for this).
397+
398+
.. configuration-block::
399+
400+
.. code-block:: jinja
401+
402+
{{ page.content|cmf_embed_blocks }}
403+
404+
.. code-block:: html+php
405+
406+
<?php echo $view['blocks']->embedBlocks(
407+
$page->getContent()
408+
) ?>
409+
410+
.. caution::
411+
412+
Make sure to only place this filter where you display the content and not
413+
where editing it, as otherwise your users would start to edit the rendered
414+
output of their blocks.
415+
This feature conflicts with the frontend editing provided by CreateBundle,
416+
as create.js operates on the rendered content as displayed to the user.
417+
There is an ongoing `discussion how to fix this`_.
418+
419+
When you apply the filter, your users can use this tag to embed a block in
420+
their content:
421+
422+
.. code-block:: text
423+
424+
%embed-block|/absolute/path/to/block|end%
425+
426+
%embed-block|local-block|end%
427+
428+
The path to the block is either absolute or relative to the current main
429+
content. The prefix and postfix are configurable. The default prefix is
430+
``%embed-block|`` and the default postfix is ``|end%``. Say you want
431+
to use ``%%%block:"/absolute/path"%%%`` then you do:
432+
433+
.. configuration-block::
434+
435+
.. code-block:: yaml
436+
437+
# app/config/config.yml
438+
cmf_block:
439+
twig:
440+
cmf_embed_blocks:
441+
prefix: '%%%block:"'
442+
postfix: '"%%%'
443+
444+
.. code-block:: xml
445+
446+
<!-- app/config/config.xml -->
447+
<?xml version="1.0" encoding="UTF-8" ?>
448+
<container xmlns="http://symfony.com/schema/dic/services">
449+
450+
<config xmlns="http://cmf.symfony.com/schema/dic/block">
451+
<twig>
452+
<cmf-embed-blocks
453+
prefix="%%%block:&quot;"
454+
postfix="&quot;%%%"
455+
/>
456+
</twig>
457+
</config>
458+
</container>
459+
460+
.. code-block:: php
461+
462+
// app/config/config.php
463+
$container->loadFromExtension('cmf_block', array(
464+
'twig' => array(
465+
'cmf_embed_blocks' => array(
466+
'prefix' => '%%%block:"',
467+
'postfix' => '"%%%',
468+
),
469+
),
470+
);
471+
472+
See also the :ref:`the configuration reference <reference-config-block-twig-cmf-embed-blocks>`.
473+
474+
.. caution::
475+
476+
Currently there is no security built into this feature. Only enable the
477+
filter for content for which you are sure only trusted users may edit it.
478+
Restrictions about what block can be where that are built into an admin
479+
interface are not respected here.
480+
481+
.. note::
482+
483+
The block embed filter ignores all errors that might occur when rendering a
484+
block and returns an empty string for each failed block instead. The errors
485+
are logged at level WARNING.
383486

384487
Examples
385488
--------
@@ -400,3 +503,4 @@ Read on
400503
.. _`Symfony CMF Sandbox`: https://github.com/symfony-cmf/cmf-sandbox
401504
.. _`prepended configuration`: http://symfony.com/doc/current/components/dependency_injection/compilation.html#prepending-configuration-passed-to-the-extension
402505
.. _`SonataBlockBundle`: https://github.com/sonata-project/SonataBlockBundle
506+
.. _`discussion how to fix this`: https://github.com/symfony-cmf/BlockBundle/issues/143

cookbook/creating_cms_using_cmf_and_sonata.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ Tree Problems
210210
-------------
211211

212212
If you have not yet added anything to the content repository, the tree view
213-
will not load as it cannot find a root node. To fix this, load some data as
214-
fixtures by following ":doc:`using_blockbundle_and_contentbundle`"
213+
will not load as it cannot find a root node. Create some content to get the
214+
tree working.
215215

216216
Further Reading
217217
---------------

cookbook/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ The Cookbook
1111
editions/cmf_core
1212
installing_configuring_doctrine_phpcr_odm
1313
creating_cms_using_cmf_and_sonata
14-
using_blockbundle_and_contentbundle
1514
handling_multilang_documents
1615
exposing_content_via_rest
1716

cookbook/map.rst.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@
1111
* :doc:`create_basic_cms_auto_routing`
1212
* :doc:`installing_configuring_doctrine_phpcr_odm`
1313
* :doc:`creating_cms_using_cmf_and_sonata`
14-
* :doc:`using_blockbundle_and_contentbundle`
1514
* :doc:`handling_multilang_documents`
1615
* :doc:`exposing_content_via_rest`

0 commit comments

Comments
 (0)