|link

|link

Twig Filter

The |link filter returns a link generated using the october:// output schema of a page finder form widget. The result is a public URL to the page specified by the form widget.

<a href="{{ 'october://cms-page@link/about'|link }}" />

If you are looking to parse HTML for multiple links and resolve them as HTTP links in the output, see the |content Twig filter.

The |link filter only returns the URL string. If you need to access nested child items from dynamic page types (like "All Blog Posts" or "All Categories"), use the link() function with the nesting option instead.

The link() function is used to extract more detailed information about a link, including dynamically generated child items.

{% set resolved = link('october://cms-page@link/about') %}

{{ resolved.url }}

The following properties can be expected in the resulting object.

Property Data
url the public URL to the page.
mtime the modification time of the page link.
title a human readable title for the link, optional.
items an array containing generated child items, optional.
isActive set to true if the link is currently active.

# Nested Items

You may request nested child items by passing the nesting option to true (second argument), which populates the items property on the result. This is essential when working with dynamic page types that generate multiple items, such as "All Blog Posts" or "All Categories".

{% set resolved = link('october://...', { nesting: true }) %}

{% for subitem in resolved.items %}
    <a href="{{ subitem.url }}">{{ subitem.title }}</a>
{% endfor %}

Each child item in the items array contains the same properties: url, title, mtime, isActive, and potentially nested items of its own for hierarchical structures.

# Replacing Parent with Children

When building menus with dynamic page types, you may want to replace a menu item with its generated children. This can be achieved by checking a stored flag and iterating the resolved items.

{% for item in menu.items %}
    {% set resolved = link(item.reference, { nesting: item.nesting }) %}

    {% if item.replace and resolved.items %}
        {# Replace parent with its generated children #}
        {% for child in resolved.items %}
            <a href="{{ child.url }}">{{ child.title }}</a>
        {% endfor %}
    {% else %}
        <a href="{{ resolved.url }}">{{ item.title }}</a>
        {% if resolved.items %}
            <ul>
                {% for child in resolved.items %}
                    <li><a href="{{ child.url }}">{{ child.title }}</a></li>
                {% endfor %}
            </ul>
        {% endif %}
    {% endif %}
{% endfor %}

You may request other site URLs by passing the sites option to true, which populates the sites property on the result.

{% set resolved = link('october://...', { sites: true }) %}

{% for site in resolved.sites %}
    {{ site.url }}
{% endfor %}

# PHP Interface

You may resolve links in PHP using the Cms\Classes\PageManager class. The url method returns a string to the public URL.

Cms\Classes\PageManager::url('october://cms-page@link/about');

The resolve method returns a detailed Cms\Models\PageLookupItem object.

$page = Cms\Classes\PageManager::resolve('october://cms-page@link/about');

echo $page->url;

# See Also