如何在组件内调用组件 [OctoberCMS]

2022-01-19 00:00:00 frontend php laravel components octobercms

我想用变量调用组件内部的组件,像这样:

I want to call a component inside a component with a variable, like this:

这是default.html的代码->

Here's the code of the default.html->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<div class="container">
    <div class="row">
        {% partial __SELF__ ~ "::category" category=__SELF__.category childscategory=__SELF__.childscategory%}
        <div class="col-xs-3">
          <strong>DATA</strong>
          <ul class="list-group text-center">
            {% partial __SELF__ ~ "::dates" files=__SELF__.files  %}
          </ul>
        </div>

        <div class="col-xs-3">
          <strong>Nome do Ficheiro</strong>
          <ul class="list-group text-center">
            {% partial __SELF__ ~ "::files" files=__SELF__.files  %}
          </ul>
        </div>

        <div class="col-xs-3">
          <strong>Descrição</strong>
          <ul class="list-group text-center">
            {% partial __SELF__ ~ "::description" files=__SELF__.files %}
          </ul>
        </div>

        <div class="col-xs-1">
          <strong>{{__SELF__.labelpresentation}}</strong>
          <ul class="list-group text-center">
            {% partial __SELF__ ~ "::download_1" files=__SELF__.files %}
          </ul>
        </div>
          -> I WANT TO CALL THE COMPONENT HERE <-
    </div>
</div>

如果你想让我发布更多类似 .php 的代码,没关系

If you want me to post more code like the .php, it's ok

推荐答案

示例:在我的 ApplicationForm 组件中使用 fileUploader 组件.在 ApplicationForm 类中,添加:

Example: use the fileUploader component in my ApplicationForm component. In ApplicationForm class, add this:

public function init()
{
    $component = $this->addComponent(
        'ResponsivUploaderComponentsFileUploader',
        'fileUploader',
        [
            'deferredBinding'   => true,
            'maxSize'           => $this->property('maxFileSize'),
            'fileTypes'         => $this->property('fileTypes'),
            'placeholderText'   => $this->property('placeholderText'),
        ]
    );

    $component->bindModel('cv', new Application());
}

并且在 ApplicationForm 组件的视图(default.htm)中使用初始化的组件,如下所示:

And in the view (default.htm) of the ApplicationForm component use the initialized component like so:

{% component 'fileUploader' %}

相关文章