verbb / craft-videoembedder

MIT License
17 stars 14 forks source link

<url> malformed Error #13

Closed danleecreates closed 4 years ago

danleecreates commented 5 years ago

I currently get the following error when a field for the URL is empty:

_Embed\Exceptions\InvalidUrlException

malformed_ As far as I can tell my code looks fine: ``` {# Video Block #} {% set videoUrl = block.video %} {% set videoEmbed = craft.videoEmbedder.getEmbedUrl(videoUrl) %} {% set providerName = craft.videoEmbedder.getProviderName(videoUrl) %} {% if videoUrl | length %}
{% if providerName == 'YouTube' %}
{% endif %} {% if providerName == 'Vimeo' %}
{% endif %}
{% endif %} ```
mikestecker commented 5 years ago

Looks like the plugin is trying to load a URL that doesn't exist. Move {% set videoEmbed = craft.videoEmbedder.getEmbedUrl(videoUrl) %} and {% set providerName = craft.videoEmbedder.getProviderName(videoUrl) %} inside the conditional like so:

{# Video Block #}
{% set videoUrl = block.video %}

{% if videoUrl | length %}
{% set videoEmbed = craft.videoEmbedder.getEmbedUrl(videoUrl) %}
{% set providerName = craft.videoEmbedder.getProviderName(videoUrl) %}
<div class="{{ padding }} {{ fontsize }}">
    <div class="{{ margin }}">

      {% if providerName == 'YouTube' %}
      <div class="aspect-ratio aspect-ratio--16x9">
            <iframe class="aspect-ratio--object" src="{{ videoEmbed }}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
      </div>
      {% endif %}

      {% if providerName == 'Vimeo' %}
      <div class="aspect-ratio aspect-ratio--16x9">
          <iframe class="aspect-ratio--object" src="{{ videoEmbed }}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
      </div>

      {% endif %}

    </div>
</div>
{% endif %}
mikestecker commented 5 years ago

Let me know if that works for you. If not, I'll try and look into it more

danleecreates commented 5 years ago

Yes that seems to be working for me now!