EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.09k stars 1.02k forks source link

how to peoperly show text content that contains html tags in easyadmin show page? #3687

Open 0x48415a484952 opened 4 years ago

0x48415a484952 commented 4 years ago

i have used ckeditor in easyAdmin3 now whenever i want to display the content it will display it like below image how to solve this issue?

jmsche commented 4 years ago

Hi, I don't know how you use CKEditor exactly, but in my project I created a CKEditorField and set the template name to crud/field/text_editor.

seb-jean commented 4 years ago

@AhmadzadehHazhir, can you show us your code to help you?

Annegren commented 3 years ago

@AhmadzadehHazhir hi, have you found the solution ? because I have the same issue

parijke commented 3 years ago

I have made a custom template for it in templates/bundles/EasyAdminBundle/crud/field/text_editor.html.twig

{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
{# @var field \EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto #}
{# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
<!-- Own template in templates/bundles/EasyAdminBundle-->
{% if ea.crud.currentAction == 'detail' %}
    {{ field.value|raw }}
{% else %}
    {% set html_id = 'ea-text-editor-' ~ field.uniqueId %}
    <a href="#" data-bs-toggle="modal" data-bs-target="#{{ html_id }}">
        <i class="far fa-file-alt"></i> {{ 'field.text_editor.view_content'|trans([], domain = 'EasyAdminBundle') }}
    </a>

    <div class="modal fade" id="{{ html_id }}" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">{{ field.label }}</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"
                            aria-label="{{ 'action.close'|trans([], domain = 'EasyAdminBundle') }}">
                    </button>
                </div>
                <div class="modal-body">
                    {{ field.formattedValue|nl2br }}
                </div>
            </div>
        </div>
    </div>
{% endif %}
Annegren commented 3 years ago

is there any configuration to do in the crudcontroller instead ?

parijke commented 3 years ago

You can set a twig template in the crud as well

Op vr 12 nov. 2021 18:37 schreef Anne Gren @.***>:

is there any configuration to do in the crudcontroller instead ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/EasyCorp/EasyAdminBundle/issues/3687#issuecomment-967293861, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2RBPWYF7YMDAXME7RHGHTULVGBPANCNFSM4QF55CUQ .

parijke commented 3 years ago

Like this:

            yield CollectionField::new('insurancePolicies')
                ->setTemplatePath('customer-policies.html.twig')
                ->onlyOnDetail();
Annegren commented 3 years ago

great many thanks :)