We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    I have a call to a snippet:
    [[+youtubevideo:!empty=`[[!ShowYouTubeClip? &clip=`[[+youtubevideo]]` ]]` ]]
    


    The problem is that the youtubevideo parameter can contain odd characters like question marks, the snippet will not execute if it sees these.

    Tried surrounding it in quotes - even before it was passed to the placeholder, still does not work.

    How can I pass a url that looks like this: http://www.youtube.com/watch?v=x9AwgIkSReI&feature=related to a snippet

    -thanks
    -sean
      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 3749
      • 24,544 Posts
      I think that would work in Revolution, but in Evolution, you need to use some other characters or character combinations for the illegal characters in the snippet tag and then use str_replace in the snippet to convert them back.



      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 33968
        • 863 Posts
        @sean - you could look at using the urlencode output modifier to encode all those funny url characters. However if the videos are always going to come from youtube then would it be possible to simply store the video id and pass that to the snippet instead?

        Eg. youtubevideo: x9AwglkSRel

        Then in your snippet you can build the youtube url back up and only return something if the clip param is not empty:
        <?php
        $output = ''
        $clip = trim($modx->getOption('clip'));
        if (!empty($clip)) {
            $url = 'htt p://www.youtube.com/watch?v=' . $clip . '&feature=related';
            // get video markup chunk
            $output = $modx->getChunk('youtube-video-markup',array('url' => $url));
        } 
        
        return $output;
        


        That way you'll also avoid output modifiers which are unfortunately not so efficient.

        [[!ShowYouTubeClip? &clip=`[[+youtubevideo]]`]]
        [ed. note: okyanet last edited this post 14 years, 4 months ago.]
          • 26503
          • 620 Posts
          Thanks guys;

          I wound up doing something like this [since there are several different formats of clip a user may enter!]

          <?php
          $clip = str_replace('QUERY','?',$clip);
          
          	// short url
          	if(stristr($clip,'youtu.be/')){
          
          		$video = explode('.be/',$clip);
          		$video =$video[1];
          		$videoclip = 'http://youtube.com/v/'.$video.'?version=3&hl=en_US';
          	
          	}
          	
          	// pasted url	
          	if(stristr($clip,'watch?v=')){
          		$querystring = explode('?',$clip);
          		$video = explode('&',$querystring[1]);
          		$video = str_replace('v=','',$video[0]);
          		$videoclip = 'http://youtube.com/v/'.$video.'?version=3&hl=en_US';  
          	}
          		
          	// default old url version
          	if(stristr($clip,'/v/')){
          		$videoclip = $clip;
          	}
          
          	
          	$youtubevideo = array();
          	$youtubevideo['videoclip'] = $videoclip;
          	
          	$output = $modx->getChunk('YouTubeVideoTpl',$youtubevideo);
          
          
          return $output;
          
            *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

            Sean Kimball CLP, CLS.
            Technical Director / Sr. Developer | BigBlock Studios
            ._______________________________________________.
            Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
            27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
            phone/fax: 905-426-5525