Skip to content

Commit

Permalink
Use render syntax and brackets for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Feb 25, 2015
1 parent 5abaec6 commit 6ab9282
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 48 deletions.
24 changes: 4 additions & 20 deletions themes/create_theme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,7 @@ multilingual pages.
$translation = $this->bindLocaleFromRoute($request, 'en');
$this->prepareThemeAssignation(null, $translation);
return new Response(
$this->getTwig()->render('foo.html.twig', $this->assignation),
Response::HTTP_OK,
array('content-type' => 'text/html')
);
return $this->render('foo.html.twig', $this->assignation);
}
public function barAction(
Expand All @@ -195,11 +191,7 @@ multilingual pages.
$this->prepareThemeAssignation(null, $translation);
return new Response(
$this->getTwig()->render('bar.html.twig', $this->assignation),
Response::HTTP_OK,
array('content-type' => 'text/html')
);
return $this->render('bar.html.twig', $this->assignation);
}
.. _dynamic-routing:
Expand Down Expand Up @@ -238,11 +230,7 @@ render your current node.
$this->getService('stopwatch')->start('twigRender');
return new Response(
$this->getTwig()->render('types/page.html.twig', $this->assignation),
Response::HTTP_OK,
array('content-type' => 'text/html')
);
return $this->render('types/page.html.twig', $this->assignation);
}
As *Symfony* controllers do, every Roadiz controllers actions have to return a valid ``Response`` object.
Expand Down Expand Up @@ -332,11 +320,7 @@ Imagine now that your home page has a totally different look than other pages. I
/*
* Render Homepage manually
*/
return new Response(
$this->getTwig()->render('home.html.twig', $this->assignation),
Response::HTTP_OK,
array('content-type' => 'text/html')
);
return $this->render('home.html.twig', $this->assignation);
}
Keep in ming that ``prepareThemeAssignation`` method will assign for you some useful variables no matter you choice
Expand Down
20 changes: 6 additions & 14 deletions themes/custom_assignations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ create a *PageController.php* which look like this:
use Themes\MyTheme\MyThemeApp;
use RZ\Roadiz\Core\Entities\Node;
use RZ\Roadiz\Core\Entities\Translation;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Frontend controller to handle Page node-type request.
Expand All @@ -49,11 +47,7 @@ create a *PageController.php* which look like this:
) {
$this->prepareThemeAssignation($node, $translation);
return new Response(
$this->getTwig()->render('types/page.html.twig', $this->assignation),
Response::HTTP_OK,
array('content-type' => 'text/html')
);
return $this->render('types/page.html.twig', $this->assignation);
}
}
Expand Down Expand Up @@ -119,9 +113,7 @@ Open your ``PageController.php`` file:
// Get BasicBlock node-type entity to filter
// over current node children
$basicBlockType = $this->getService('nodeTypeApi')
->getOneBy(
'name' => 'BasicBlock'
);
->getOneBy(['name' => 'BasicBlock']);
// Assign blocks using current nodeSource children
// filtering them by node-type (only BasicBlock nodes
Expand All @@ -132,12 +124,12 @@ Open your ``PageController.php`` file:
$this->assignation['nodeSource']
->getHandler()
->getChildren(
array(
[
'node.nodeType' => $basicBlockType
),
array(
],
[
'node.position' => 'ASC'
),
],
$this->getService('securityContext')
);
Expand Down
23 changes: 9 additions & 14 deletions themes/extending_roadiz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Example:
use Themes\Rozier\RozierApp;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
class AdminController extends RozierApp
Expand All @@ -44,11 +43,7 @@ Example:
$this->getService('stopwatch')->start('twigRender');
return new Response(
$this->getTwig()->render('admin/test.html.twig', $this->assignation),
Response::HTTP_OK,
array('content-type' => 'text/html')
);
return $this->render('admin/test.html.twig', $this->assignation);
}
}
Expand Down Expand Up @@ -126,13 +121,13 @@ or create it if it doesn’t exist.
/*
* Add a customAdmin entry in your Backoffice
*/
$entries['customAdmin'] = array(
$entries['customAdmin'] = [
'name' => 'customAdmin',
'path' => $c['urlGenerator']->generate('adminTestPage'),
'icon' => 'uk-icon-cube',
'roles' => null,
'subentries' => null
);
];
return $entries;
});
Expand All @@ -148,21 +143,21 @@ If you want to have a category and sub-entries, just change the path at ``null``

.. code-block:: php
$entries['customAdmin'] = array(
$entries['customAdmin'] = [
'name' => 'customAdmin',
'path' => null,
'icon' => 'uk-icon-cube',
'roles' => null,
'subentries' => array(
'customAdminPage' => array(
'subentries' => [
'customAdminPage' => [
'name' => 'customAdmin page',
'path' => $c['urlGenerator']->generate('adminTestPage'),
'icon' => 'uk-icon-cube',
'roles' => null
),
],
// Add others if you want
)
);
]
];
You can restrict buttons to users with specific roles. Just replace ``'roles' => null`` with
``'roles' => array('ROLE_ACCESS_NODES')``. You can even create your own roles to take full power of
Expand Down

0 comments on commit 6ab9282

Please sign in to comment.