[Flow] Using Layout from other package

Christian Loock chl at vkf-renzel.de
Wed Jul 31 10:20:25 CEST 2013


Hey,

wow, you are my hero. Thanks for sharing this.

So what i did, based on your code: I added one method to the controller 
that needs to use the layout of another package.

/**
         *
         * @param ViewInterface $view
         */
         protected function 
initializeView(\TYPO3\Flow\Mvc\View\ViewInterface $view) {
             parent::initializeView($view);
             /** @var \TYPO3\Fluid\View\TemplateView $view */
$view->setLayoutRootPath('resource://BasePackage/Private/Layouts');

         }

Using the setLayoutRootPath allows you to determine the layout which you 
want to use in the template itself.

This is pretty cool stuff, however, i still think thats not the cleanest 
way to do, but at the moment it seems to be the only way.

What would be cool to have:

Add a parameter to the layout ViewHelper to controll which Package to 
use. Something Like this:

<f:layout name="MyLayout" package="Vendor.Packagename" />

I also tried writing my own ViewHelper that loads any template from a 
given package, but couldnt really figure out how to do it :(

Something like loading partials, but not being limited to files in the 
partials folder of your own Package would also be great to have:

<f:include file="any/depth/of/subfolders/in/template/dir/foo.html" 
package="Vendor.Packagename" />

Am 31.07.2013 09:59, schrieb Qbus | Axel Wüstemann:
> This was developed by Robert Lemke within a workshop he holded in our 
> company:
>
> The key is, to let all controller derive from a master controller, 
> wich defines a layoutRootPath und a partialRootPath.
>
> Furher, each module may define a function 'getModuleLabel' and 
> 'getModuleCssClass' in order to generate a dynamic and plugable menu.
>
> abstract class AbstractModuleController extends ActionController {
>
> /**
> * @Flow\Inject
> * @var \TYPO3\Flow\Reflection\ReflectionService
>  */
> protected $reflectionService;
>
> /**
> * @Flow\Inject
> * @var \TYPO3\Flow\Object\ObjectManagerInterface
> */
> protected $objectManager;
>
> /**
> *
> *
> * @param ViewInterface $view
> */
> protected function initializeView(ViewInterface $view) {
> parent::initializeView($view);
> /** @var \TYPO3\Fluid\View\TemplateView $view */
> $view->setLayoutPathAndFilename('resource://LALLF.Intranet/Private/Layouts/Default.html');
> $view->setPartialRootPath('resource://LALLF.Intranet/Private/Partials/');
> $view->assign('modules', $this->buildMenu());
> }
>
>
> /**
> * @return string
> */
> static public function getModuleCssClass() {
> return '';
> }
>
> /**
> * @return array
> */
> protected function buildMenu() {
> $moduleClassNames =
> $this->reflectionService->getAllImplementationClassNamesForInterface('LALLF\Intranet\Controller\ModuleControllerInterface'); 
>
>
> $modules = array();
> foreach ($moduleClassNames as $moduleClassName) {
> $objectName = 
> $this->objectManager->getObjectNameByClassName($moduleClassName);
> $packageKey = 
> $this->objectManager->getPackageKeyByObjectName($objectName);
>
> $modules[$moduleClassName] = array(
>     'label' => call_user_func(array($moduleClassName, 'getModuleLabel')),
>     'package' => $packageKey,
>     'controller' => substr($moduleClassName, strpos($moduleClassName, 
> '\\Controller\\') + 12, -10),
>     'icon' => call_user_func(array($moduleClassName, 
> 'getModuleCssClass')),
>     'active' => (get_class($this) === $moduleClassName)
> );
> }
>
> return $modules;
> }
>
> }
> _______________________________________________
> Flow mailing list
> Flow at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow



More information about the Flow mailing list