Rendering a component partial from code in OctoberCMS
According to this section of the OctoberCMS documentation, it should be possible for me to set up a directory structure like this:
pluginname
├── components
│ ├── resumefilter
│ │ ├── default.htm
│ │ └── my-partial.htm
│ ├── ResumeFilter.php
│ ├── resumelist
│ │ └── default.htm
│ └── ResumeList.php
Then, I should be able to put a function in ResumeFilter.php
like this:
function onFilterResumes()
{
return ['#someDiv' => $this->renderPartial('my-partial.htm')];
}
Finally, a button in the default.htm
markup:
<button
class="btn btn-success"
data-request="onFilterResumes">
Filter
</button>
The problem is, when I press the button, it says The partial 'my-partial.htm' is not found
I've tried it with the full path but it doesn't seem to make any difference.
October seems to be looking in the theme partials directory for the partial because it loads if I put it in there. However, prefixing the name with resumefilter:
to try and get it to look in the component isn't working, and the docs seem to suggest that it should be looking in the component without a prefix.
I found this bug on github from 2 years ago but it looks like it was fixed.
Answer
Add @
before your partial name if you want to render component partial. So your code should like this,
function onFilterResumes()
{
return ['#someDiv' => $this->renderPartial('@my-partial.htm')];
}
And if you want to override the partial in your theme, put the partial in the following tree,
themes/theme-name/partials/component-name/my-partial.htm
Related Questions
- → OctoberCMS Backend Loging Hash Error
- → "failed to open stream" error when executing "migrate:make"
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → Create plugin that makes objects from model in back-end
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → How to install console for plugin development in October CMS
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → How to update data attribute on Ajax complete
- → October CMS - Conditionally Load a Different Page