如何从组件中呈现部分主题

How can I render a theme partial from within a component

我想在多个插件和组件之间重用模态部分。根据随主题提供的 Bootstrap 版本,模式可能具有不同的属性,因此我决定在每个主题中创建一个模式以在站点范围内使用。当我更改主题时,我只是在主题中添加适当编码的部分。

然后我的组件可以在需要时使用所需的变量渲染模态。

我的解决方案如下:

 public function modalSet($sections) {
        $modal_path = $this->getTheme()->getPath() . '/partials/site/modal.htm';

        return ['#modal' => $this->renderPartial($modal_path,
            [
                'title' => array_get($sections, 'title', ''),
                'subhead' => array_get($sections, 'subhead', ''),
                'body' => array_get($sections, 'body', ''),
                'foot' => array_get($sections, 'foot', ''),
            ]),
        ];
    }


    onShowInfo(){
        return $this->modalSet([
                'title' => 'Information About The Thing',
                'body' => '<p>The thing is really Big</p>',
        ]);
    }

问题是 $this->renderPartial 试图在组件中找到部分而不是主题,即使我传递了整个主题部分路径。

我收到错误:“找不到页面 '/home/kurt/public_html/mysite/themes/mytheme/partials/site/modal.htm'”

那么我需要做什么才能从组件内部渲染主题部分?

theme partials 它们几乎没有区别 acting differently from regular partials。他们有点 Halcyon Model // 有点跑题

好的,这是方法。

just use name with directory [ make sure you use .htm extension for your partial files its needed. and site folder must be inside partials folder ]

    // use this path it will respect current active theme
    // and pick partial from active theme automatically 

    $modal_path = 'site/modal.htm'; 
    return ['#modal' => $this->renderPartial($modal_path,
        [
            'title' => array_get($sections, 'title', ''),
            'subhead' => array_get($sections, 'subhead', ''),
            'body' => array_get($sections, 'body', ''),
            'foot' => array_get($sections, 'foot', ''),
        ]),
    ];

它会做一些技巧并从目录加载部分内容并给你 desired html

如有疑问请评论。