default.html does not show when creating a component in octobercms

194 views Asked by At

I have a problem displaying the default.htm file of the component I created. I can drag and drop the component into a page or partial but will not display anything.

What I currently have:

  • Component called {% component 'researchResources' %}
  • it is already listed in the components menu

Problem: When I drag and drop the component to a specific part of a page, it does not show anything.

Steps when testing the 'author/plugin/component/default.htm' file:

Static: <h1>Test component</h1>

Dynamic:

<ul>
  {% for item in __SELF__.resources %}
    <li> {{ item.name }} </li>
  {% endfor %}
</ul>

either ways are not showing on the part where the component has been registered or placed. Am I missing something? Or did I make a mistake?

Other files

'Author/Plugin/Components/Resources.php' file:

<?php namespace Author\Researchresources\Components;

use Cms\Classes\ComponentBase;
use Author\Researchresources\Models\ResearchResource;

class Resources extends ComponentBase
{

    public function componentDetails(){
        return [
            'name' => 'Resources List',
            'description' => 'List of Research Resources'
        ];
    }

    public function onRun(){
         $this->resources = $this->loadResources();
    }

    protected function loadResources(){
        return ResearchResource::all();
    }

    public $resources;

}

'Author/Plugin/Plugin.php' file:

<?php 
namespace Author\Researchresources;

use System\Classes\PluginBase;

class Plugin extends PluginBase
{
  public function registerComponents(){
    return [
      'Author\Researchresources\Components\Resources' => 'researchResources'
    ];
  }

  public function registerSettings()
  {
  }

  public function boot(){
    \Event::listen('offline.sitesearch.query', function ($query) {
      $controller = \Cms\Classes\Controller::getController() ?? new \Cms\Classes\Controller();

      $research_resources = ResearchResource::where('name', 'like', "%${query}%")->orWhere('description', 'like', "%${query}%")->get();

      $results = $research_resources->map(function ($item) use ($query, $controller) {

        $relevance = mb_stripos($item->name, $query) !== false ? 2 : 1;
        
        return [
            'title'     => $item->name,
            'text'      => $item->description,
            'url' => ($item->content_url != null) ? $item->content_url : "",
            'relevance' => $relevance,
        ];
      });

      return [
        'provider' => 'Document', // The badge to display for this result
        'results'  => $results,
      ];
    });
  }
}
1

There are 1 answers

0
Kawin Cheong On

Directory folder should be lowercase