page
Usage
The | page
filter creates a link to a CMS page, using a page file name without an extension as a parameter. For example, if there is an about.htm
page in your Winter install, you can use the following code to generate a link to it:
If your page resides in a subdirectory, you should also specify the subdirectory name:
NOTE: The Themes documentation has more details on subdirectory usage.
To access the link to a certain page from the PHP section, you can use $this->pageUrl('page-name-without-extension')
:
You can create a link to the current page by using an empty string:
To get the link to the current page in PHP, you can use $this->pageUrl('')
with an empty string.
Reverse routing
When linking to a page that has URL parameters defined, the | page
filter supports reverse routing by passing an array as the first argument.
For example, if you have a file called post.htm
with the following URL defined for displaying blog posts:
You can link to a specific blog post by providing the post_id
parameter to the first argument for the page
filter:
If the website address is https://wintercms.com
, the above example would output the following:
Persistent URL parameters
If a URL parameter is already present and used in the current page, the | page
filter will use it automatically.
Using the above example, if you have a file called edit-post.htm
with the following URL defined for editing blog posts:
You can create a link within the original post.htm
to this edit page without specifying a post ID to edit the current post:
This will output the following:
The post_id
value of 10
is already known and has persisted across the pages. If you do not want this behaviour to occur, you can disable this functionality by passing false
as the filter argument:
Or by defining a different value: