This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I'm currently facing the following challenge: I have a component that renders markup by having a default.htm in the plugins folder, which in turn includes a partial (let's say: include.htm).
Now, while I want to share the functionality of the component across different themes, I want to be able to override the included partial (i.e., include.htm) in the respective theme when required.
No problem so far, you just need to have your overriding include in themes/
However, I'd also like to be able to use that same component twice (or more times) on the same page, but using different component parameters, so that my users are able to use the brilliant component inspector thing when they edit the page. So for example, let's assume I use that include.htm to just render
<div>Hello {{name}}</div>
..where "name" is a component property and I'd like to be that name to be "Adam" on the first usage of the component, and "Bob" on the second. (Just a stupid example for the sake of simplicity).
Also not a problem, I just need to give the component an alias and then use
{% component 'mycomponent' %}
on its first usage on the page, and
{% component 'mycomponent' mycomponent-second %}
or something.
Only when I do this, the overriding partial from that theme does not kick in any more, since when looking up the theme-specific path for that partial, October apparently uses the component alias as the path component it expects include.htm to be located at, not the name of the component.
So unless I copy that same include.htm into another folder named
themes/<mytheme>/partials/<mycomponent-second>
October will then use the partial from the plugin directory.
Any ideas? Am I missing something?
i had the same requirement yesterday and my workaround is the following : you need to add your 2 compoennts in your page or layout, lets called them myComp1 and myComp2 in the component php code, i define a property called 'withPartial' which will contain a name of the partial i want to display by the component. so in the cms page, on myComp1 you can set the withPartial value to myPartial1 and myPartial2 for the myComp2 2 things to finish this :
- serving the property to the component in the onRun method of the component
$this->withPartial = $this->page['withPartial'] = $this->property('withPartial');
- then in the default.html partial of the component, you can have soemthng like
{% if withPartial %} {% set partialName = '@' ~ withPartial %} {% partial partialName%} {% else %}
Your Default HTML component
{% endif %}
hope that helps
Last updated
1-2 of 2