Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering a component partial from code in OctoberCMS

Tags:

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.

like image 811
Joseph Avatar asked Feb 19 '17 11:02

Joseph


1 Answers

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

like image 72
Surahman Avatar answered Oct 04 '22 12:10

Surahman