【问题标题】:How do I call a component inside a component [OctoberCMS]如何在组件内调用组件 [OctoberCMS]
【发布时间】:2016-10-17 18:33:37
【问题描述】:

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

这是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 的代码,没关系

【问题讨论】:

  • 别偷懒,贴出真实的代码sn-ps而不是截图,这样可以帮助别人重用你的代码来回答你的问题。

标签: php laravel components frontend octobercms


【解决方案1】:

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

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

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

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

{% component 'fileUploader' %}

【讨论】:

  • $component-&gt;bindModel('cv', new Application()); 部分对我来说是一个 Class not found 错误。省略它效果很好。
猜你喜欢
  • 2018-04-12
  • 2015-01-10
  • 1970-01-01
  • 2016-11-06
  • 1970-01-01
  • 2019-04-12
  • 2016-12-22
  • 2020-09-25
  • 2015-11-08
相关资源
最近更新 更多