Overriding Views


Related Links

Introduction

Often times you will need to change a view in a core addon or the streams platform. In order to avoid hacking up your installation, PyroCMS makes it easy to override views from your own addons, theme, or within your project specifically.

Theme Overrides

Theme overrides are a great way to bundle view overrides into your theme. To get started simply copy the desired view you would like to override into your active theme's resources/views/addons directory using the following pattern:

{theme_path}/resources/views/addons/{vendor}/{addon}-{type}/{view}

To override the posts/partials/posts.twig view in the posts module for example:

{theme_path}/resources/views/addons/anomaly/posts-module/posts/partials/posts.twig

Streams Platform Views

You can override views in the streams platform following a similar pattern:

{theme_path}/resources/views/streams/{view}

To override the forms/partials/layout.twig view in the streams platform for example:

{theme_path}/resources/views/streams/forms/partials/layout.twig

Addon Service Provider Overrides

Service provider overrides are a great way to distribute view overrides to your projects or others. Every addon supports overrides through their addon service provider. The $overrides array provides view => override definitions and the $mobile array can provide the same for mobile agents specifically:

protected $overrides = [
    'streams::errors/404' => 'theme::errors/404',
    'streams::errors/500' => 'theme::errors/500',
];

protected $mobile = [
    'anomaly.module.posts::posts/index' => 'theme::overrides/posts/index',
];

View overrides in public themes will not affect the admin theme.

Manually Registering Overrides

You can also use the \Anomaly\Streams\Platform\View\ViewOverrides collection directly to add view overrides dynamically. The service provider again is a good place to do this though you can inject the singleton anywhere:


use Anomaly\Streams\Platform\View\ViewOverrides;

public function register(ViewOverrides $overrides) {
    $overrides->add('streams::errors/404', 'theme::errors/404');
}

Published Views

Publishing addons and the streams platform is a good way to override views per project. They are committed to your VCS and are fast and easy to do. To get started simply publish the addon:

php artisan addon:publish anomaly.module.posts

You can find the published files in your application resources directory:

/resources/{app_reference}/addons/{vendor}/{addon}-{type}/views/{path}

Simply change the views as needed and delete the rest that don't need to be overridden.

Streams Platform Views

You can publish and override views in the streams platform following a similar pattern:

php artisan streams:publish

The published files are again in your application resources directory:

/resources/{app_reference}/streams/views/{path}