简体   繁体   中英

IvoryCKEditorBundle Symfony: How to use “ckeditor_widget” from IvoryCKEditorBundle TWIG template in my OWN redefined TWIG template

I've implemented IvoryCKEditorBundle in my SYMFONY 3.2 project.

I followed the guidelines from here and had an overview of the doc on the official Symfony site .

Now I see the following files exits in the IvoryCKEditorBundle directory:

  • [my project]\\vendor\\egoloen\\ckeditor-bundle\\Resources\\views\\Form\\ckeditor_widget.html.twig
  • [my project]\\vendor\\egoloen\\ckeditor-bundle\\Twig\\CKEditorExtension.php

And [my project]\\vendor\\egoloen\\ckeditor-bundle\\Resources\\views\\Form\\ckeditor_widget.html.twig defines {% block ckeditor_widget %} .

In my projet I have redefined my own template to render a form, using all the tricks given in the official doc . And under [my project]\\src\\MyBundle\\Resources\\views I have a file input_inline_template.html.twig which looks like that:

{% extends 'form_div_layout.html.twig' %}
{% use 'CKEditorBundle:Form:ckeditor_widget.html.twig' %}
{% block form_row  %}
   <div    class='col-12'  id={{ id ~ '_div_row_id'}}>
        {% block form_label   %}
         <div class='col-4' id={{ id ~ '_div_label_id' }}>
            {{ parent() }}
          </div>
        {% endblock %}

        {% if form.vars.block_prefixes.2 == "textarea" %}
            {% if (form.vars.block_prefixes.3 is defined) and (form.vars.block_prefixes.3 == "ckeditor") %} 
             {% block ckeditor_widget %}
                 <div class='col-8'>
                  {{ parent() }}
                 </div>
             {% endblock %}
         {% else %}
            {% block textarea_widget %}
                <div class='col-8'>
                  {{ parent() }}
                 </div>
            {% endblock %}
        {% endif %}
     {% endif %}
   </div>
{% endblock %}

This does not work. It tells me that it cannot find the ckeditor_widget if I don't have the line {% use 'CKEditorBundle:Form:ckeditor_widget.html.twig' %} it throws the error:

Block "ckeditor_widget" on template "form_div_layout.html.twig" does not exist in "form_div_layout.html.twig".

And when the line {% use 'CKEditorBundle:Form:ckeditor_widget.html.twig' %} is implemented, it throws an error that is:

Unable to find template "CKEditorBundle:Form:ckeditor_widget.html.twig"

It tells me it looks for CKEditorBundle:Form:ckeditor_widget.html.twig in: [my_symf_project]\\app/Resources/views , [my_symf_project]\\vendor\\symfony\\symfony\\src\\Symfony\\Bridge\\Twig/Resources/views/Form , [my_symf_project]\\vendor\\knplabs\\knp-menu\\src\\Knp\\Menu/Resources/views .

I don't know how to configure in [my project]\\app\\config\\config.yml that it should look in [my project]\\vendor\\egoloen\\ckeditor-bundle\\Resources\\views\\Form\\ to find ckeditor_widget.html.twig .

I found a hint here .

In [my project]\\src\\MyBundle\\Resources\\views\\input_inline_template.html.twig , I've replaced: {% use 'CKEditorBundle:Form:ckeditor_widget.html.twig' %} with: {% use 'IvoryCKEditorBundle:Form:ckeditor_widget.html.twig' %} .

It fixed it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM