in my layout i have things like meta tags etc. that may change in e.g. in different static sites.
Example:
if i go to
/static/about
i would like to have a different meta-description as in
/static/contact
My Problem is that i would like to change these variables/values inside the view script static/content/about or static/content/contact and NOT in the controller.
How can i do that?
Take a look at the view helper: PlaceHolders
Take a look at this post may it useful for u :
http://blog.ggshow.com/index.php/reference/zend-framework-view-helper-placeholder
Related
I am creating a slightly elaborated form with Angular. This form can be submitted, then modified or simply displayed (with everything in read-only for example).
For now I have 3 templates with 3 controllers for each action (submit / edit / view) and the form is added as a partial (ng-include). The form has also its own controller. Is it the right way?
Also, should I make the form's controller the children of the templates' controllers or the opposite? I am using the same model for each action behind the form and I guess it should be injected through the template's controller.
It's my very first attempt to do this and I would like to have a few advice's and hints since I am afraid of going the wrong way. Thank you!
yo can use different template for each of them with single controller, different controller for each of them is not a good idea because there may be some common function in them then you need to write that function in each of them.
you can use common model for them,i am doing the same.
I see this is promising solutions to what you are looking for
can you try this http://vitalets.github.io/angular-xeditable/#editable-form
I am trying to create a sidebar in my layout that has the behavior of a placeholder. I want to be able to define the contents of this placeholder once per controller. So every controller can add custom content to the sidebar but without the need to define it in any view.
I am kind of confused on how to go about that with Zend_Layout. Any help?
I have tried something similar. Here is what you can do.
Place this type of code in the layout.phtml script file. Somewhere near the top. You don't have to but this way you 'know' what placeholders you're using. Doing this in the layout is also a good idea because you can wrap html divs are whatever here and not worry about it in the views. The views can just worry about the content. After this, you can add content to the placeholders from the controllers and the views.
$this->placeholder('blah');
$this->placeholder('sidebar');
$this->placeholder('blunk');
If you don't want to create them in your layout, then you can do it in the controller like so,
$this->view->placeholder( 'sidebar');
.
Now, you can either put content into it in the controller, or in the view script. Its a better idea to add the content in the view though.
In the layout you can then just echo the placeholders like so
echo $this->placeholder->( 'sidebar' );
All the views are executed BEFORE the layout is executed so any placeholders created by the views will be available to the layout to print out.
Also, controllers don't HAVE placeholders. Only views, and by extension layout, have placeholders like this so you have to declare them somewhere. Even if you declare them in the controller they still 'belong' to the view object.
I don't know if this helps at all but good luck. Tell me what you think.
How about adding a postDispatch() call to each controller?
public function postDispatch()
{
// code to populate/activate your placeholder
$this->view->placeholder('xxx');
}
This function will be called after your action completes. For more info, see Pre- and Post-Dispatch Hooks.
i have just implemented a solution to this that should work for most uses.
I store all of my placeholder.phtml files in the following dir:
/views/scripts/_placeholder
Within the placeholder i create directories for each Controller / Action that has a placeholder (as well as ROOT stuff). I then create a file for each placeholder.
e.g. Placeholder = sidebar. Controller = user / action = view
for the above we would store a file here:
views/scripts/_placeholder/user/view/sidebar.phtml
note: within the sidebar.phtml you will need to add : $this->placeholder("sidebar")->captureStart() and captureEnd();
if the plugin sees this file it will render it. If it doesnt find one then it wont.
Additionally the plugin will also look for the following and pull that in first:
views/scripts/_placeholder/sidebar.phtml
I can post the plugin if you want.
The only issue i have is i would like to now know if a placeholder has any data in it. That way i can create some layouts that are clever and will render what needs. DOes anyone know how to do this?
i need to show variables in part of layout(i know placeholder is useful!) but this variables assigning in actions of controller, so i need render of view be after action running and this variables will show in all of pages (like menu but not exastly).
some of actions load with ajax!
what is your idea?! what is best way?
If I understand your question, Action Helpers might be what you are looking for. Take a look at the documentation http://framework.zend.com/manual/en/zend.controller.actionhelpers.html
Am using N2 CMS and want to know how I can create an editable item that can be included in the header of every page within the site.
I just want to be able to edit this piece of text in one place and have the text appear on every page.
I understand that I need to create a "Part" but I'm not sure how to create the edit interface for this one "part"
Thanks.
Late answer but IT might help the others. You can use it as following.
#{ Html.DroppableZone(Content.Traverse.StartPage, "EDITABLEPART").Render(); }
A simpler approach (to parts) might be to:
add a property to your homepage ContentItem which is decorated with EditableTextBox or EditableFreeTextBox.
edit the homepage to set the text
then in your layout/masterpage you can simply include the output from this property
We use this technique for storing the Google Analytics tracking code against the homepage and it then gets rendered on every page.
It sounds like you need a recursive zone. Here's an example: https://github.com/jamestharpe/HereSay/blob/master/src/HereSay/Decorators/SectionalZoneDecorator.cs
Using that code, all you need to do is name your zone beginning with "Sectional" (e.g. "SectionalTopZone") and the plug-in will take care of the rest.
For an example of an editable part, you can take a look at the code here: https://github.com/jamestharpe/HereSay/blob/master/src/HereSay/Parts/HtmlContentBlock.cs
how can I pass an object model to a view, that is partial view on a master page?
regards
You might consider creating an another object that more closely represents the view you are trying to render.
Let's say i have an MyDomain.Order object, so I make a view page that looks something like ViewPage<MyDomain.Order>. Now, let's say that I have a menu that is driven off of a logged in user, as example. It wouldn't make sense to have menu as a property of MyDomain.Order. I would create another object, specifically for the view, call it something like OrderPageModel and have MyDomain.Order and List<MenuItem> as properties of this new object, my view being set up as ViewPage<OrderPageModel>.
The other thing to consider might be something like Html.RenderAction(). Same scenario, I have a view, and as you mention in your question, it has a master page, and as in my example, lets say it hosts a menu common to your site. You could create a partial view (UserMenu.ascx) and a controller (SiteController.cs) with an action (UserMenu) that calculates the items for the menu. Inside your master page, you can then call <% Html.RenderAction("UserMenu","SiteController") %>.
I would use the first example if it could be something made for a particular view: just make it a part of the model. I would use the second example if it was something more generic to the site, like a menu.
You could specify the location of the view:
return PartialView("~/Views/SomeOtherController/SomePartial.ascx", someModel);
Best bet here is RenderAction over RenderPartial. Your child controller can easily figure out if the user is logged in and render the right partial rather than making your master page worry about these details.