<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect3 id="zend.view.helpers.initial.doctype">
    <title>Doctype Helper</title>

    <para>
        Valid <acronym>HTML</acronym> and <acronym>XHTML</acronym> documents should include a
        <constant>DOCTYPE</constant> declaration. Besides being difficult to remember, these can
        also affect how certain elements in your document should be rendered (for instance,
        CDATA escaping in <emphasis>&lt;script&gt;</emphasis> and
        <emphasis>&lt;style&gt;</emphasis> elements.
    </para>

    <para>
        The <classname>Doctype</classname> helper allows you to specify one of the
        following types:
    </para>

    <itemizedlist>
        <listitem><para><constant>XHTML11</constant></para></listitem>
        <listitem><para><constant>XHTML1_STRICT</constant></para></listitem>
        <listitem><para><constant>XHTML1_TRANSITIONAL</constant></para></listitem>
        <listitem><para><constant>XHTML1_FRAMESET</constant></para></listitem>
        <listitem><para><constant>XHTML1_RDFA</constant></para></listitem>
        <listitem><para><constant>XHTML_BASIC1</constant></para></listitem>
        <listitem><para><constant>HTML4_STRICT</constant></para></listitem>
        <listitem><para><constant>HTML4_LOOSE</constant></para></listitem>
        <listitem><para><constant>HTML4_FRAMESET</constant></para></listitem>
        <listitem><para><constant>HTML5</constant></para></listitem>
    </itemizedlist>

    <para>
        You can also specify a custom doctype as long as it is well-formed.
    </para>

    <para>
        The <classname>Doctype</classname> helper is a concrete implementation of the
        <link linkend="zend.view.helpers.initial.placeholder">Placeholder helper</link>.
    </para>

    <example id="zend.view.helpers.initial.doctype.basicusage">
        <title>Doctype Helper Basic Usage</title>

        <para>
            You may specify the doctype at any time. However, helpers that
            depend on the doctype for their output will recognize it only after
            you have set it, so the easiest approach is to specify it in your
            bootstrap:
        </para>

        <programlisting language="php"><![CDATA[
$doctypeHelper = new Zend_View_Helper_Doctype();
$doctypeHelper->doctype('XHTML1_STRICT');
]]></programlisting>

        <para>
            And then print it out on top of your layout script:
        </para>

        <programlisting language="php"><![CDATA[
<?php echo $this->doctype() ?>
]]></programlisting>
    </example>

    <example id="zend.view.helpers.initial.doctype.retrieving">
        <title>Retrieving the Doctype</title>

        <para>
            If you need to know the doctype, you can do so by calling
            <methodname>getDoctype()</methodname> on the object, which is returned by
            invoking the helper.
        </para>

        <programlisting language="php"><![CDATA[
$doctype = $view->doctype()->getDoctype();
]]></programlisting>

        <para>
            Typically, you'll simply want to know if the doctype is <acronym>XHTML</acronym> or
            not; for this, the <methodname>isXhtml()</methodname> method will suffice:
        </para>

        <programlisting language="php"><![CDATA[
if ($view->doctype()->isXhtml()) {
    // do something differently
}
]]></programlisting>

        <para>
            You can also check if the doctype represents an <acronym>HTML5</acronym> document.
        </para>

        <programlisting language="php"><![CDATA[
if ($view->doctype()->isHtml5()) {
    // do something differently
}
]]></programlisting>
    </example>

    <example id="zend.view.helpers.initial.doctype.xhtml1_rdfa">
        <title>Choosing a Doctype to Use with the Open Graph Protocol</title>

        <para>
            To implement the <ulink url="http://opengraphprotocol.org/">
            Open Graph Protocol</ulink>, you may specify the XHTML1_RDFA doctype.
            This doctype allows a developer to use the <ulink url="http://www.w3.org/TR/xhtml-rdfa-primer/">
            Resource Description Framework</ulink> within an <acronym>XHTML</acronym> document.
        </para>

        <programlisting language="php"><![CDATA[
$doctypeHelper = new Zend_View_Helper_Doctype();
$doctypeHelper->doctype('XHTML1_RDFA');
]]></programlisting>

        <para>
        The RDFa doctype allows XHTML to validate when the 'property'
        meta tag attribute is used per the Open Graph Protocol spec.  Example
        within a view script:
        </para>

        <programlisting language="html"><![CDATA[
<?php echo $this->doctype('XHTML1_RDFA'); ?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:og="http://opengraphprotocol.org/schema/">
<head>
   <meta property="og:type" content="musician" />
]]></programlisting>

        <para>
            In the previous example, we set the property to og:type. The og references
            the Open Graph namespace we specified in the html tag.
            The content identifies the page as being about a musician.  See
            the <ulink url="http://opengraphprotocol.org/">Open Graph Protocol documentation</ulink>
            for supported properties. The <link linkend="zend.view.helpers.initial.headmeta">HeadMeta helper</link>
            may be used to programmatically set these Open Graph Protocol meta tags.
        </para>

        <para>
            Here is how you check if the doctype is set to XHTML1_RDFA:
        </para>

        <programlisting language="php"><![CDATA[
<?php echo $this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml"
      <?php if ($view->doctype()->isRdfa()): ?>
      xmlns:og="http://opengraphprotocol.org/schema/"
      xmlns:fb="http://www.facebook.com/2008/fbml"
      <?php endif; ?>
>
]]></programlisting>

    </example>
</sect3>
<!--
vim:se ts=4 sw=4 et:
-->
