该 |link 过滤器返回一个使用 页面查找器表单小部件 的 october:// 输出方案生成的链接。结果是由该表单小部件指定的页面的公共 URL。
<a href="{{ 'october://cms-page@link/about'|link }}" />如果你希望解析 HTML 以获取多个链接,并将其解析为输出中的 HTTP 链接,请参阅
|contentTwig 过滤器。
:::
配套的 link() 函数用于提取关于链接的更详细信息。
{% set resolved = link('october://cms-page@link/about') %}
{{ resolved.url }}以下属性可以在结果对象中预期。
| 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. |
您可以请求嵌套的子项,方法是将 nesting 选项设置为 true (第二个参数),这会在结果中填充 items 属性。
{% set resolved = link('october://...', { nesting: true }) %}
{% for subitem in resolved.items %}
{{ subitem.url }}
{% endfor %}您可以通过将 sites 选项设置为 true 来请求其他站点 URL,这会填充结果上的 sites 属性。
{% set resolved = link('october://...', { sites: true }) %}
{% for site in resolved.sites %}
{{ site.url }}
{% endfor %}您可以使用 Cms\Classes\PageManager 类解析 PHP 中的链接。 url 方法返回一个公共 URL 字符串。
Cms\Classes\PageManager::url('october://cms-page@link/about');该 resolve 方法返回一个详细的 Cms\Models\PageLookupItem 对象。
$page = Cms\Classes\PageManager::resolve('october://cms-page@link/about');
echo $page->url;