Skip to content

Instantly share code, notes, and snippets.

@wouterj
Last active December 29, 2015 13:39
Show Gist options
  • Select an option

  • Save wouterj/7679194 to your computer and use it in GitHub Desktop.

Select an option

Save wouterj/7679194 to your computer and use it in GitHub Desktop.
<!doctype html>
<title>{{ cmfMainContent.title }}</title>
<h1>{{ cmfMainContent.title }}</h1>
{# added cmf_embed_blocks filter
{{ cmfMainContent.body|raw|cmf_embed_blocks }}
<?php
use Symfony\Cmf\Bundle\ContentBundle\Doctrine\Phpcr\StaticContentBase;
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
use PHPCR\Util\NodeHelper;
// ...
NodeHelper::createPath($session, '/cms/content');
NodeHelper::createPath($session, '/cms/routes');
$contentRoot = $documentManager->find(null, '/cms/content');
$content = new StaticContentBase();
$content->setTitle('My very own article!');
$content->setBody('Yeah, I finally feel like I\'m smart! [block:dummy-block]'); // include block string
$content->setParent($contentRoot);
$content->setName('my-article');
$documentManager->persist($content);
// new block stuff
$block = new StringBlock();
$block->setBody('Hello world, I\'m a block!');
$block->setName('dummy-block');
$block->setParentDocument($content);
$documentManager->persist($block);
$routesRoot = $documentManager->find(null, '/cms/routes');
$route = new Route();
$route->setPosition($routesRoot, 'my-article');
$route->setContent($content); // link content to route
$documentManager->persist($route);
$documentManager->flush();
cmf_content:
default_template: ::content.html.twig # bad practise, but it'll do for now
cmf_routing:
chain:
routers_by_id: # make sure to register the router
cmf_routing.dynamic_router: 200
router.default: 100
dynamic:
controllers_by_class:
Symfony\Cmf\Bundle\ContentBundle\Doctrine\Phpcr\StaticContent: cmf_content.controller:indexAction
# added block config
sonata_block:
default_contexts: [cms]
cmf_block:
twig:
cmf_embed_block:
prefix: "[block:"
postfix: "]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment