2.9.2. General Helpers

All helpers automatically apply appropriate escaping. This means you can use {{= ... }} to output them. If you use {{h ... }} et al., you will end up double-escaping the output.

You can also address the helpers as methods on $this in PHP template code.

Finally, many of these helpers accept a trailing variadic list of named parameters as HTML tag attributes. This means you can add just about any attribute as if it was a parameter on the helper method. Underscores in the parameter name will be converted to dashes; e.g., foo_bar: 'baz' will become foo-bar="baz" in the returned helper output. For attributes that cannot double as named parameters, use the attr array parameter; for example:

{{= anchor (
    'http://qiqphp.com',
    'Qiq Project',
    attr: [                 // (array) optional key-value attributes
        'xml:lang' => 'en',
    ],
    id: 'qiq-link',         // (...mixed) optional named parameter attributes
) }}

The example code will produce this HTML:

<a href="http://qiqphp.com" xml:lang="en" id="qiq-link">Qiq for PHP</a>

2.9.2.1. anchor

Helper for <a> tags.

{{= anchor (
    'http://qiqphp.com',    // (string) href
    'Qiq Project',          // (string) text
    attr: [],               // (array) optional key-value attributes
    id: 'qiq-link',         // (...mixed) optional named parameter attributes
) }}
<a href="http://qiqphp.com" id="qiq-link">Qiq for PHP</a>

2.9.2.2. base

Helper for <base> tags.

{{= base (
    '/base'                 // (string) href
) }}
<base href="/base" />

2.9.2.3. dl

Helper for <dl> tags with <dt>/<dd> items.

{{= dl (
    [                       // (array) dt keys and dd values
        'foo' => 'Foo Def',
        'bar' => [
            'Bar Def A',
            'Bar Def B',
            'Bar Def C',
        ],
        'baz' => 'Baz Def',
    ],
    attr: [],               // (array) optional key-value attributes
    id: 'test'              // (...mixed) optional named parameter attributes
) }}
<dl id="test">
    <dt>foo</dt>
        <dd>Foo Def</dd>
    <dt>bar</dt>
        <dd>Bar Def A</dd>
        <dd>Bar Def B</dd>
        <dd>Bar Def C</dd>
    <dt>baz</dt>
        <dd>Baz Def</dd>
</dl>

2.9.2.4. image

Helper for <img> tags.

{{= image (
    '/images/hello.jpg',    // (string) image href src
    attr: [],               // (array) optional key-value attributes
    id: 'image-id'          // (...mixed) optional named parameter attributes
) }}
<!-- if alt is not specified, uses the basename of the image href -->
<img src="/images/hello.jpg" alt="hello" id="image-id" />

2.9.2.5. items

Helper for a series of <li> tags.

{{= items ([                // (array) list items
    'foo',
    'bar',
    'baz'
]) }}
<li>foo</li>
<li>bar</li>
<li>baz</li>

2.9.2.6. link

Helper for a <link> tag.

{{= link (
    rel: 'prev',
    href: '/path/to/prev',
    attr: [],               // (array) optional key-value attributes
    id: 'link-id'           // (...mixed) optional named parameter attributes
) }}
<link rel="prev" href="/path/to/prev" id="link-id" />

2.9.2.7. linkStylesheet

Helper for a <link> stylesheet tag.

{{= linkStylesheet (
    '/css/print.css',       // (string) the stylesheet href
    attr: [],               // (array) optional key-value attributes
    media: 'print'          // (...mixed) optional named parameter attributes
) }}
<!-- if type is not specified, uses "text/css" -->
<!-- if media is not specified, uses "screen" -->
<link rel="stylesheet" href="/css/print.css" type="text/css" media="print" />

2.9.2.8. meta

Helper for a <meta> tag.

For general use:

{{= meta (
    attr: [],               // (array) optional key-value attributes
    ...                     // (...mixed) optional named parameter attributes
) }}

For charset:

{{= meta (
    charset: 'utf-8'
) }}
<meta charset="utf-8">

For http-equiv:

{{= meta (
    http_equiv: 'Location',
    content: '/redirect/to/here'
) }}
<meta http-equiv="Location" content="/redirect/to/here">

For name:

{{= meta (
    name: 'author',
    content: 'Qiq for PHP'
) }}
<meta name="author" content="Qiq for PHP">

2.9.2.9. ol

Helper for <ol> tags with <li> items.

{{= ol (
    [                       // (array) list items
        'foo',
        'bar',
        'baz'
    ],
    attr: [],               // (array) optional key-value attributes
    id: 'foo-list'          // (...mixed) optional named parameter attributes
) }}
<ol id="foo-list">
    <li>foo</li>
    <li>bar</li>
    <li>baz</li>
</ol>

2.9.2.10. script

Helper for a <script> tag.

{{= script (
    '/js/functions.js',     // (string) src attribute
    attr: [],               // (array) optional key-value attributes
    async: true             // (...mixed) optional named parameter attributes
) }}
<!-- if type is not specified, uses "text/javascript" -->
<script src="/js/functions.js" type="text/javascript" async></script>

2.9.2.11. ul

Helper for <ul> tags with <li> items.

{{= ul (
    [                       // (array) list items
        'foo',
        'bar',
        'baz'
    ],
    attr: [],               // (array) optional key-value attributes
    id: 'foo-list'          // (...mixed) optional named parameter attributes
) }}
<ul id="foo-list">
    <li>foo</li>
    <li>bar</li>
    <li>baz</li>
</ul>