This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hey there,
I've written two plugins for our website. One that provides creating projects (title, description, category - simliar to a blogpost) and one for creating image-sliders. I now want a project to reference a slider by its slug (which is already integrated) and load this specific slider by the slider component into the single project component's markup. Therefor I have to tell the slider component which slider-slug is saved in the project. I am able to get the slider's slug like I do it with the other project elements in the markup ( {{ project.slider }} = slug of the slider that should be loaded ) but I can't pass this information to the slider component before it gets the slider elements (images etc.) which makes the slider appear empty.
I tried passing the variable to the component like so:
{% component 'slider' idParam=project.slider %}
but it doesn't work because passing variables only works in the onRender function, but I'm getting the slider-elements from the database in the onRun function of the component. Is there a way to pass a variable from one component into the onRun function of another component? Or maybe there's a workaround I didn't think of.
Thanks in advance! :)
Last updated
I think you can use another plugin model in your component
<?php namespace YourName\PluginName\Models
use RainLab\Blog\Models\Post;
...
...
public function getSlides()
{
$posts = Post::all();
$slides = [];
foreach ($posts as $post) {
if ( count($post->featured_images()) ) {
$slides = $post->featured_images()->first()->getThumb(800, 300, crop);
}
}
return $slides;
}
But I'm not sure that this decision is correct.
Last updated
Interesting. If you can't use the onRender function, then I think some refactoring would serve you best. If the project has a slider, wouldn't it be better to reference that in the project model by specifying a relation, either hasMany or belongsTo? It's a bit too early for me to figure out which one you're after sorry.
1-3 of 3