BitBagCommerce / SyliusCmsPlugin

Content management system for eCommerce apps created on Sylius platform. Built with Sylius code quality, flexibility, BDD.
MIT License
235 stars 159 forks source link

Ignore twig syntax in ckeditor #178

Closed muldos closed 6 years ago

muldos commented 6 years ago

Hi, I've used the new feature of twig syntax available in admin panel (https://github.com/BitBagCommerce/SyliusCmsPlugin/blob/master/doc/twig-functions-in-admin.md). I've also noticed that ckeditor is sanitizing

{{ bitbag_cms_render_media('IMGQDM1') }}

and so it doesn't works with a WYSIWYG field.

I've fixed it in my sylius project by doing the following :

1 - I've created a template ckeditor_widget.html.twig

{# app/Resources/Form/ckeditor_widget.html.twig #}
{% extends 'FOSCKEditorBundle:Form:ckeditor_widget.html.twig' %}

{% block ckeditor_widget_extra %}
    {% set regexTwig = '/{{\s*([^{]*{([^{]*):\s*(.*?)}.*?|[^{]*)\s*}}/g' %}
    CKEDITOR.dtd.$removeEmpty['span'] = false;
    CKEDITOR.config.protectedSource.push( {{ regexTwig }} );
{% endblock %}

In my config.yml

twig:
    paths:
        '%kernel.project_dir%/app/Resources/views': App
        '%kernel.project_dir%/app/Resources/views/Admin': BackOffice
        '%kernel.project_dir%/app/Resources/views/Shop': FrontOffice
    form_themes:
                - "@BackOffice/Form/ckeditor_widget.html.twig"

So now I can use {{ bitbag_cms_render_media('IMGQDM1') }} syntax inside a wysiwyg managed field.

I don't know if this fix could be natively integrated to cms plugin but it would be great I think.

Best regards, David

bitbager commented 6 years ago

Hi! 2.0.0 was just released and I checked if nesting Twig in WYSIWYG works and it does. Could you check if you still face the problem?

muldos commented 6 years ago

Hi, I've update to 2.0.0 and it's ok now ! Thanks for the fix.

bitbager commented 6 years ago

No problem :)