1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect3 id="zend.view.helpers.initial.headtitle">
4 <title>HeadTitle Helper</title>
7 The <acronym>HTML</acronym> <emphasis><title></emphasis> element is used to provide a
8 title for an <acronym>HTML</acronym> document. The <classname>HeadTitle</classname> helper
9 allows you to programmatically create and store the title for later retrieval and output.
13 The <classname>HeadTitle</classname> helper is a concrete implementation of the
14 <link linkend="zend.view.helpers.initial.placeholder">Placeholder
15 helper</link>. It overrides the <methodname>toString()</methodname> method to
16 enforce generating a <emphasis><title></emphasis> element, and adds a
17 <methodname>headTitle()</methodname> method for quick and easy setting and
18 aggregation of title elements. The signature for that method is
19 <methodname>headTitle($title, $setType = null)</methodname>; by default, the
20 value is appended to the stack (aggregating title segments) if left at null, but you may
21 also specify either 'PREPEND' (place at top of stack) or 'SET'
26 Since setting the aggregating (attach) order on each call to <methodname>
27 headTitle</methodname> can be cumbersome, you can set a default attach order
28 by calling <methodname>setDefaultAttachOrder()</methodname> which is applied
29 to all <methodname>headTitle()</methodname> calls unless you explicitly
30 pass a different attach order as the second parameter.
33 <example id="zend.view.helpers.initial.headtitle.basicusage">
34 <title>HeadTitle Helper Basic Usage</title>
37 You may specify a title tag at any time. A typical usage would have
38 you setting title segments for each level of depth in your
39 application: site, controller, action, and potentially resource.
42 <programlisting language="php"><![CDATA[
43 // setting the controller and action name as title segments:
44 $request = Zend_Controller_Front::getInstance()->getRequest();
45 $this->headTitle($request->getActionName())
46 ->headTitle($request->getControllerName());
48 // setting the site in the title; possibly in the layout script:
49 $this->headTitle('Zend Framework');
51 // setting a separator string for segments:
52 $this->headTitle()->setSeparator(' / ');
56 When you're finally ready to render the title in your layout
57 script, simply echo the helper:
60 <programlisting language="php"><![CDATA[
61 <!-- renders <action> / <controller> / Zend Framework -->
62 <?php echo $this->headTitle() ?>