October CMS resources and help articles

Simple and to the point. Optimized by the community.

Get a combined list of CMS and Static Pages

1
by OFFLINE, last modified on August 11th, 2019

Sometimes it is necessary to assign a model to a specific page. Just add a simple dropdown to your fields.yaml:

basefile:
    label: 'Associated Page'
    span: auto
    type: dropdown

And the following code to your model:

public function getBasefileOptions()
{
    // get default pages
    $pages = \Cms\Classes\Page::sortBy('baseFileName')->lists('title', 'baseFileName');

    // also add static pages if the Pages plugin is installed.
    if (class_exists('\\Rainlab\\Pages\\Classes\\Page')) {
        $pages = $pages + \Rainlab\Pages\Classes\Page::sortBy('title')
                                                     ->lists('title', 'baseFileName');
    }

    return $pages;
}

In the backend the user gets a dropdown with all CMS- and Static-Pages and saving the record the associated filename will be saved.

Discussion

1 comment

0
mittulAtTechnobrave
Post on October 17th, 2019 11:16 AM

How can I redirect at front ? I want to redirect properly with full url .. can you please provide me twig redirection for page redirect ?

We use cookies to measure the performance of this website. Do you want to accept these cookies?