0

As the title suggests, I'm trying to find a way of displaying the title of the View currently being displayed as part of the layout. I'm trying to do this so that the page title is dynamicly populated when a different view is selected.

In psuedocode:

<div>
   <div id="header"><h1>My website</h1></div>
   <div id="main">
           <?php echo "<h2>" . SOME WAY OF ECHOING THE VIEW NAME HERE . "</h2>"; ?>
           <?php echo $this->layout()->content; ?>
   </div>
   <div id="footer"><p>2011 My website.com></p>
</div>

I've been through the Zend documentation and the closest thing I could find was the headlink. However, I was unable to get the value from this helper and shoehorn it into a variable so that I could display its text as a page header for the view.

Thanks.

8bitjunkie
  • 12,793
  • 9
  • 57
  • 70

2 Answers2

1

I´m not quite sure if I understood you right, but there´s something called a placeholder in ZendFramework. Basically you define the placeholder and fill it afterwards with whatever you want.

and_the_rand
  • 307
  • 2
  • 7
  • You're on the right lines. What I am looking for is a standard placeholder which I can use in my layout, in order to print the title of the current view in a div container above the view. My thinking is that I could then add some CSS to this heading, thus creating a consistent document title on each of the pages in my application. – 8bitjunkie Oct 27 '11 at 14:40
1

You could pass the action name (or combine with the module if needed) to the layout within the controller.

$layout = $this->_helper->layout->getLayoutInstance(); $layout->viewName = $this->_getParam("action");

Kind of dirty, but it would work

Patrick
  • 685
  • 5
  • 12
  • Thanks for your suggestion. The best I can come with is to wrap your code suggestion into a private method in my controller, which accepts a String of text. Instead of calling the _getParam action, I call this private method from each action method in turn, and set the page text to the value supplied as an argument. Unfortunately there doesn't appear to be a standard Placholder for this - I'm very surprised! – 8bitjunkie Oct 27 '11 at 14:52