0

I want to build a fancy headline container which - you'll never guess it - contains the title of each page displayed.

In Django you can either create a variable in every view which is passed to the layout page or define a block which is filled with content on the content page.

Its not such a nice solution copy and pasting my fancy header on every page of my application just to put my page title in. I'd prefer to put the headline container in my layout page and use my $title variable to set the title within the container.

I found a solution for static variables here but I need a dynamic variable because the title is different for every page.

My question: Is there an easy way to pass the $title variable which I have on every content page to my layout.phtml?

Thanks!

Community
  • 1
  • 1
Ron
  • 22,128
  • 31
  • 108
  • 206

2 Answers2

1

There is a nice view Helper in ZF for this task. You can define what Title you want to use for your page in your view files.

In your view pages:

//index.tmpl
$this->headTitle("this is my unique title for this page");

In your Layout file :

<title><?php echo $this->headTitle() ?></title>

And more info at: http://framework.zend.com/manual/2.0/en/modules/zend.view.helpers.head-title.html

Al-Punk
  • 3,531
  • 6
  • 38
  • 56
  • I use this `headTitle()` function but AFAIK its for the title tag as you outlined. I want a regular div to be a headline for my content, just like a `

    ` tag. Because my title is more code than just

    I'd like to put it centerally into the layout - if possible.

    – Ron Dec 19 '12 at 10:26
  • Have a look at ZF Placeholders then. – Al-Punk Dec 19 '12 at 11:48
0

Ok, the answer is quite simple if you know what to look for. Use the placeholder helper.

//layout.phtml
<?php $this->placeholder('foo')->set("Some text for later") ?>

and

//myview.phtml
<?php
   echo $this->placeholder('foo');
   // outputs "Some text for later"
?>
Ron
  • 22,128
  • 31
  • 108
  • 206