Youtube / Vimeo embed resizer

Resizes a Youtube / Vimeo embed code from a Template variable with the variables given in the snippet call…

1- Create a new Snippet and call it  videoresizer
2- Copy – paste the content of videoresizer.snippet.txt on your new snippet
3- Enjoy!

Example: [[videoresizer? &id='[*id*]’ &width=’300′ &height=’350′ &my_tv=’video’]]


//    Snippet Name: videoresizer
//    Snippet variables: id , width, height, my_tv (all required)
//    --Requires Getfield Snippet--
//    Example:  [[videoresizer? &id=`[*id*]` &width=`300` &height=`350` &my_tv=`video`]]

$video=$modx->runSnippet("getField", array('docid'=>$id,'field' =>$my_tv));

$embed = preg_replace('/(width)=("[^"]*")/i', 'width=$width', $video);
$embed = preg_replace('/(height)=("[^"]*")/i', 'height=$height', $embed);

echo $embed;

Every Sunrise delivers Opportunities While every sunset asks what we did with the opportunities…

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch