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

alex6972
alex6972

I've developed a plugin that has a component which also acts as a snippet for static pages. The component has one parameter. I've discovered that when I have multiple instances of the same snippet with different parameter values, the values get overwritten by that of the last instance. As a result instead of different content blocks that vary depending on the parameter it outputs the same block x times over. It works as expected as a component with non-static pages - no duplicates.

Am I doing something wrong? Please advise.

Component code:

<?php namespace Bigbuzz\Company\Components;

use Cms\Classes\ComponentBase;
use Bigbuzz\Company\Models\Company;

class Brand extends ComponentBase
{
    public $brand;

    public function componentDetails()
    {
        return [
            'name'        => 'Brand Component',
            'description' => 'Company information block.'
        ];
    }

    public function defineProperties()
    {
        return [
            'company' => [
                'title'       => 'Company',
                'type'        => 'dropdown',
                'placeholder' => 'Select company'
            ]
        ];
    }

    public function getCompanyOptions()
    {
        $companies = Company::where('is_active', true)->orderBy('sort_order', 'asc')->get();
        $options = [];
        foreach ($companies as $company) {
            $options[$company->id] = $company->name;
        }
        return $options;
    }

    public function onRun()
    {
        $this->brand = Company::find($this->property('company'));
    }

}

Corresponding default.htm:

<div class="container brand">
    <div class="col-md-5 text-center">
        <img src="{{ __SELF__.brand.logo|media }}">
    </div>
    <div class="col-md-7">
        <h4>{{ __SELF__.brand.name }}</h4>
        {{ __SELF__.brand.about|raw }}
        <p><a href="{{ __SELF__.brand.website_url }}" target="_blank">Visit website</a></p>
    </div>
</div>
alex6972
alex6972

OK, I've narrowed this down to the fact that I'm using a bleeding edge build (346). Works fine on a stable build (318).

1-2 of 2

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