viget / craft-video-embed
Generate an embed URL from a YouTube or Vimeo URL
Installs: 56 743
Dependents: 0
Suggesters: 0
Security: 0
Stars: 24
Watchers: 27
Forks: 4
Open Issues: 3
Type:craft-plugin
Requires
- craftcms/cms: ^4.0.0
README
Generate an embed URL from a YouTube or Vimeo URL.
Requirements
This plugin requires Craft CMS 4.0.0 or later.
Installation
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require viget/craft-video-embed
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for Video Embed.
Using Video Embed
Pass a YouTube or Vimeo URL to the getVideoData
method and a VideoData
object is returned.
If the plugin is unable to parse the URL, null
is returned.
type
- If the video isyoutube
orvimeo
id
- The ID of the videoimage
- The thumbnail of the video (only works for Youtube)embedUrl
- The URL you would use for the embedurl
- The link to the embedded video
Example:
{% set video = craft.videoEmbed.getVideoData('https://www.youtube.com/watch?v=6xWpo5Dn254') %} {% if video %} <iframe src="{{ video.embedUrl }}"></iframe> {% endif %}
Output:
<iframe src="//www.youtube.com/embed/6xWpo5Dn254"></iframe>
Visit code.viget.com to see more projects from Viget.