We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19369
    • 1,098 Posts
    Hi, I am trying to create a snippet that change the size of a video automatically.

    My snippet is called youtube
    <?php
    $Input = $modx->getTemplateVarOutput('video-01');
        $Input = $Input['video-01'];
    
        $Input= preg_replace('/width="640"/', 'width=570', $Input);
        $Input= preg_replace('/height="505"/', 'height=338', $Input);
    
        $Input= preg_replace('/width="480"/', 'width=570', $Input);
        $Input= preg_replace('/height="390"/', 'height=338', $Input);
        return $Input;
    ?>


    the html: [[youtube]]

    The problem is that I have 30 template variables, named video-01,video-02,video-03 and so on, so I would like to put the TV inside the snippet call, like this [[youtube? &Input=`[*video-01*]`]].

    I have already tried but it doesn’t work. it returns stuff like this
    <object widt" 
    ><object widt 			   >


    Does anyone have any idea or suggestion?
      • 31381
      • 31 Posts
      your post is old and I don’t have an answer, but a hint:

      $Input= preg_replace(’/height="505"/’, ’height=338’, $Input);

      on the search string there are double quotes around the number, in the replace string there aren’t.
      Is that correct for what you want to happen?

        • 19369
        • 1,098 Posts
        Thanks Vegano, I have already solved it

        This is the snippet
        <?php
        $Input = $modx->getTemplateVarOutput('video-'.$num);
            $Input = $Input['video-'.$num];
        
            $Input= preg_replace('/width="640"/', 'width=630', $Input);
            $Input= preg_replace('/height="505"/', 'height=360', $Input);
        
            return $Input;
        ?>


        This the call:
        [[youtube? &num=`01`]]