This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

dragontree
dragontree

I'm building an e-shop and I need to link to CMS pages. For example, I need to put the terms and conditions link in to a components view. How do I get the link for the CMS page?

I dont want to use the slug as the slug might be changed.

dragontree
dragontree

Found a solution for the CMS pages. Basically we need to add a custom field for the page and then fetch the page url using that field.

Add the custom field in the plugin boot method:

Event::listen('backend.form.extendFields', function($widget) {
        // CMS Page controller and model
        if ($widget->getController() instanceof \CMS\Controllers\Index && $widget->model instanceof \CMS\Classes\Page){
            $widget->addFields([
                'settings[hook]' => [
                    'label'   => 'Hook',
                    'type'    => 'text'
                ]
            ]);
        }
    });

And now we can get the page like this:

$page = CMSPage::where('hook', 'cms-test')->first();

Havent figured out how to fetch a static page using the same way

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.