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