pages-plugin: Snippet overrides not working properly

When adding 2 or more snippets of the same type on the same static page, the data-snippet alias changes. This breaks the template override because the app is looking for a folder that isn’t there. As a result, only the first snippet renders using the override and the others use the default template.

EDIT: This only seems to happen with snippets coming from components, as when adding multiple snippets coming from partials on the same page does not change their data-snippet property.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 15 (13 by maintainers)

Most upvoted comments

@LukeTowers
On a customer’s project I created snippets from component for a view on an organisational chart model.
I created 6 symlinks in my partials folder thinking I was safe.
Well no, the customer used the snippet 7 times in the page; as a result I got a call to ask why a simple addition didn’t have the same effect on the page.

From the point of view of considering the CMS part of OctoberCMS as a reserved domain for the developer, and to leave only one access to the Pages plugin for the customer; it doesn’t work with the same flexibility anymore.

I can no longer keep this solution, I will modify my component in the same way as @mrdrarek to take into account an additional property to define the value of the partial to be used.
I just corrected a small mistake.

public function defineProperties()
{
    return [
        'template_alias' => [
            'title'             => 'Alias to be used for the partial',
            'description'       => '',
            'default'           =>  '',
            'type'              => 'string'
        ],
    ];
}

public function onRender()
{
    ($this->property('template_alias')) ?  $this->alias = $this->property('template_alias') : '';
}