How do I call a component inside a component [OctoberCMS]

谁都会走 提交于 2019-12-07 09:36:33

问题


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

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>

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


回答1:


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

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());
}

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

{% component 'fileUploader' %}


来源:https://stackoverflow.com/questions/37855845/how-do-i-call-a-component-inside-a-component-octobercms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!