@@ -33,7 +33,7 @@ individually as follows:
33
33
34
34
.. code-block :: yaml
35
35
36
- cmf_core :
36
+ cmf_block :
37
37
persistence :
38
38
phpcr :
39
39
block_basepath : /cms/content
@@ -43,7 +43,7 @@ individually as follows:
43
43
<?xml version =" 1.0" charset =" UTF-8" ?>
44
44
<container xmlns =" http://symfony.com/schema/dic/services" >
45
45
46
- <config xmlns =" http://cmf.symfony.com/schema/dic/core " >
46
+ <config xmlns =" http://cmf.symfony.com/schema/dic/block " >
47
47
<persistence >
48
48
<phpcr
49
49
block-basepath =" /cms/block"
@@ -55,7 +55,7 @@ individually as follows:
55
55
56
56
.. code-block :: php
57
57
58
- $container->loadFromExtension('cmf_core ', array(
58
+ $container->loadFromExtension('cmf_block ', array(
59
59
'persistence' => array(
60
60
'phpcr' => array(
61
61
'block_basepath' => '/cms/block',
@@ -328,6 +328,10 @@ time a block is rendered before the ``execute`` method is called.
328
328
Block rendering
329
329
---------------
330
330
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
+
331
335
To render the example from the :ref: `bundle-block-document ` section, just add
332
336
the following code to your Twig template:
333
337
@@ -378,8 +382,107 @@ receives the block object (equivalent to a Request object) and a ``Response``
378
382
object. The purpose of the ``execute `` method to set the content of the
379
383
response object - typically by rendering a Twig template.
380
384
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:" "
454
+ postfix =" " %%%"
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.
383
486
384
487
Examples
385
488
--------
@@ -400,3 +503,4 @@ Read on
400
503
.. _`Symfony CMF Sandbox` : https://github.com/symfony-cmf/cmf-sandbox
401
504
.. _`prepended configuration` : http://symfony.com/doc/current/components/dependency_injection/compilation.html#prepending-configuration-passed-to-the-extension
402
505
.. _`SonataBlockBundle` : https://github.com/sonata-project/SonataBlockBundle
506
+ .. _`discussion how to fix this` : https://github.com/symfony-cmf/BlockBundle/issues/143
0 commit comments