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

RuslanZavacky
RuslanZavacky

I use blog plugin and I want to modify data before output it to template. In template.htm I have onStart function, and I have a plugin with name sliders. How to iterate sliders and create new field based on data sliders provide? (I need this field to be as parameter in slider record).

function onStart() {
    // this does not work.
    foreach ($this['sliders'] as $slider) { 
         var_dump($slider);
    }
}

Thanks!

Last updated

OctoDevel
OctoDevel

Hello RuslanZavacky,

As your sliders plugin return an array you need to put & an ampersand before the variable $slider, like bellow:

function onStart() {
    // this does not work.
    foreach ($this['sliders'] as &$slider) { 
         $slider['my_custom_field'] = 'any value here';
         // Or you can modify an existing array key, like bellow
         $slider['existent_key'] = 'new value';
         var_dump($slider);
    }
}

Is this what you are needing?

Last updated

1-2 of 2

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