1

I'm getting a Deprecated Warning on the property safeHtml:

The embedded asset property safeHtml is now deprecated. Use a combination of the isSafe() method and the code property instead.

This is picked up on line 4 and 11 of the code below:

        {# if video embed #}
        {% if embed.type == 'video' %}
            <div class="aspect-ratio aspect-ratio--16x9">
                {% set vidcode = embed.isSafe() | trim('<iframe') %}
                {% set vid = '<iframe class="aspect-ratio--object" ' ~ vidcode %}
                {{ vid|raw }}
            </div>
        {# else if rich embed #}
        {% else %}
            <div class="w-100 w-75-ns center">
                {{ embed.isSafe()|raw }}
            </div>
        {% endif %}

How do I update this code correctly to remove the warning?

1

Since it appears that you are using Craft CMS 3, you can try the purify filter.

In your code, change this line:

{% set vidcode = embed.isSafe() | trim('<iframe') %}

To something like:

{% set vidcode = embed | purify | trim('<iframe') %}

Documentation:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.