Managing multiple layouts using Zend_Layout? - zend-framework

I am trying to implement a templating sytem in zend framework.
I basically use to put all the partials files and template variation in one file, but as the templates are increasing this is beign highly unmanageable.
for example
/application/layout/script/template1partial-banner.phtml
/application/layout/script/template1partial-footer.phtml
/application/layout/script/template1variation1.phtml
/application/layout/script/template1variation2.phtml
/application/layout/script/template2variation1.phtml
/application/layout/script/template2variation2.phtml
You can see, how unmanageable this is
so i want to manage it under this structure
/application/layout/script/template1/partial/banner.phtml
/application/layout/script/template1/partial/footer.phtml
/application/layout/script/template1/variation/1.phtml
/application/layout/script/template1/variation/2.phtml
/application/layout/script/template2/partial/banner.phtml
/application/layout/script/template2/partial/footer.phtml
/application/layout/script/template2/variation/1.phtml
/application/layout/script/template2/variation/2.phtml
Well defining the partials is not a problem, you can just use $this -> render($this -> getTemplateName()."/partials/banner.phtml");
Its the variations, that is main problem
I used $this -> _helper -> layout -> setLayout('template1variation1'); before, but for the new thing I can't use it, now.
How can i do something this?

You can also define a complete path in your layout function.
$this->_helper->layout->setLayout('template1/partial/banner');
One Other way to do this task is to disable layout for your current action and then render it to any phtml file. For example first disable layout for current action
$this->_helper->layout->disableLayout();
Then just render to any html file like this
$this->render("complete path to your phmtl file");

Related

Can I select the layout to use for a page with Wyam?

I'm working on a theme for Wyam and I'm wondering if there's a way to set the layout that should be used in the markdown file for a particular page. As far as I have seen so far, it seems that each page created with markdown uses _Layout.cshtml
To be more specific. I'm creating an "about.md" page, which has a different layout then then other (default) pages.
So what I would like to do is use metadata to select the layout. For example
Layout: _About.cshtml
or
Layout: _About
Is this possible with Wyam?
In A Razor File
Pages in the Wyam recipes (I'm assuming you're using either the blog or docs recipe) are processed by Razor. The use of a _Layout.cshtml is by convention in the recipe, but alternate layouts can be specified using standard Razor syntax. You can do so by placing the following at the top of the about page .cshtml file (under your front matter):
#{
Layout = "_About.cshtml";
}
In A Markdown File
Markdown files are also processed by the Razor engine, so the technique above would work if it weren't for the Markdown processor escaping the # symbol. There's really no good way around that, and the simple answer to your question is you can't specify an alternate layout for a Markdown file.
However, one of the advantages of using a code-driven generator like Wyam is that you have a lot of control. In this case, you can replace the RenderPages pipeline with one that will do exactly what you want. Add the following to your wyam.config file:
int index = Pipelines.IndexOf(Blog.RenderPages);
Pipelines.Remove(Blog.RenderPages);
Pipelines.Insert(index, Blog.RenderPages,
(IPipeline)new Wyam.Web.Pipelines.RenderPages(
Blog.RenderPages,
new Wyam.Web.Pipelines.RenderPagesSettings
{
Pipelines = new string[] { "Pages" },
Layout = (doc, ctx) => doc.String("Layout", "/_Layout.cshtml")
}));
Then you'll be able to add a "Layout" value as front matter exactly like you wrote in your question.
This was a good idea in general, so I've also opened an issue to add this behavior to the recipe by default.

Can i add more colors in tx_gridelements

i want to add more backend colors in Typo3 Gridelements.
Under Typo3 -> List -> CE Backend Layout is an Option "Frame" with 4 colors and i want to add more colors.
Is there a way for it?
Best Regards
You probably want to use something like this in your pageTS:
TCEFORM.tx_gridelements_backend_layout{
frame{
addItems{
10 = unicorn-pink
}
}
}
You can change every field from every table with this method.
See https://docs.typo3.org/typo3cms/TSconfigReference/PageTsconfig/TCEform/Index.html for further information about this.
Just adding the value in TCEFORM might not be enough, since you will need to add CSS to get the colors assigned to those new classes.
So you will at least need to have a small extension providing the items, a basic folder structure as in the usual sitepackages and the CSS embedded via ext_tables.php and/or ext_localconf.php

Zend View Helper - Dependent Files, Images, CSS, JS

What is the best way to structure or package a view helper that will display a reusable flash chart based on passed data?
Should the structure looks something like this, or is it overkill? I would like to keep the files separate from the general public app files.
-application
---module
----default
------views
--------helpers
----------MyFlashChart.php
-public
---images
---css
---js
---default
------views
--------helpers
----------MyFlashChart
------------js
------------css
------------images
------------swf
I guess technically I will be using a partial in combination..
Read the docs:
http://framework.zend.com/manual/en/project-structure.project.html

Action specific JS Script just like view scripts

By default, every action has its specific view script like index.phtml for index action. However more to this, I also want to have js script specifics to actions as well. like index.js for index action.
I tried to use $this -> view -> headScript() -> prependScript('myjsfile.js');, but the script is added to top and not at the bottom as I was hoping for. I suppose a helper would do the trick. but i dont know how to create it. or there is a better solution of what i am hoping for.
Even though I appendFile from the action, the files which are appended from the layout file always seems to come at last. Which is not what I want, I want files in the layout file to be loaded first and then the script provided in the action method.
try
$this->view->headScript()->appendFile('myjsfile.js');
instead of prepend!
you can altough define an order for the files:
$this->headScript()->offsetSetFile(1, 'myjsfile1.js')
->offsetSetFile(2, 'myjsfile2.js');

Line breaks in Zend Navigation Menu labels

I have a need to create a <br/> tag in the display label for a menu item generated using Zend_navigation, but don't seem to be able to find a way to do so.
My navigation item is defined in the XML config as:
<registermachine>
<label>Register your Slitter Rewinder</label>
<controller>service</controller>
<action>register</action>
<route>default</route>
</registermachine>
I want to force a tag in the output HTML between 'your' and 'slitter', such that it appears on two line as below:
Register your
Slitter Rewinder
However, I can't seem to do it. obviously using in the XML breaks parsing, and using html entities means that the lable is displayed as:
Register your <br/>Slitter Rewinder
Has anyone had experience of this that can offer advice?
Thanks in advance!
there is no such option built-in you have to use a partial
$partial = array('menu.phtml', 'default');
$this->navigation()->menu()->setPartial($partial);
echo $this->navigation()->menu()->render();
http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.navigation.menu
you may also try a hack with <label><![CDATA[Menu label<br/>Second line]]></label>
I found a (hacky) solution:
I updated my navigation.xml to use {br} tokens wherever a <br/> tag is required, and then amended the base Zend/View/Helper/Navigation/Menu.php file as follows:
within htmlify function, changed
$this->view->escape($label)
to
str_replace("{br}", "<br/>", $label)
I could (and probably will) override the Zend Library Menu View Helper with my own at some point, but this at least cover it for now.
there is a escapeLabels boolean used to convert html tags and it's true by default.
You can set your navigation like this
$this->navigation()
->menu()
->escapeLabels(false)
->...
http://framework.zend.com/apidoc/2.0/classes/Zend.View.Helper.Navigation.Menu.html#escapeLabels