Winter CMS resources and help articles

Simple and to the point. Optimized by the community.

Add a CMS Page reference to your model (Dropdown select)

1
by skripteria, last modified on October 30th, 2021

Sometimes you may want a reference to a specific CMS Page for filtering purposes.

This can be done with just a few lines of code:

  • add a field to your models database ('cmspage'' in this example)

  • to fields.yaml add:


cmspage:
        label: File
        type: dropdown
  • to YourModel.php add:

public function getCmspageOptions($value, $formData) {
        return \Cms\Classes\Page::getNameList();
    }

This will save the (base-)filename of the selected page which then can be used for filtering purposes.

Discussion

0 comments

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