【问题标题】:default.html does not show when creating a component in octobercms在 octobercms 中创建组件时 default.html 不显示
【发布时间】:2026-01-26 06:00:02
【问题描述】:

我在显示我创建的组件的 default.htm 文件时遇到问题。我可以将组件拖放到页面或部分中,但不会显示任何内容。

我目前拥有的:

  • 组件调用{% component 'researchResources' %}
  • 它已在组件菜单中列出

问题: 当我将组件拖放到页面的特定部分时,它不显示任何内容。

测试“author/plugin/component/default.htm”文件的步骤:

静态: <h1>Test component</h1>

动态:

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

这两种方式都不会显示在已注册或放置组件的部分上。我错过了什么吗?还是我弄错了?

其他文件

'作者/插件/组件/Resources.php'文件:

<?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;

}

'作者/插件/Plugin.php'文件:

<?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,
      ];
    });
  }
}

【问题讨论】:

  • 你的default.htm 应该在这里'author/plugin/components/&lt;resources&gt;/default.htm' 然后它会显示。不在'author/plugin/components/default.htm'
  • 我们有相同的目录。我刚刚发现目录文件夹应该都是小写的。感谢您的帮助!
  • 当然,非常欢迎 :)

标签: laravel octobercms octobercms-plugins octobercms-backend octobercms-builder


【解决方案1】:

目录文件夹应为小写

【讨论】: