We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    Hi;

    I have a couple hundred videos I need to post on a site, sometimes several per page I already have some template variables setup to pass some stuff to the script that will display the video [height, width, path, name etc] & I thought the best way to do this, i.e. easiest for the client would be to set up the videos as static resources so that all the client needs to do is browse to the file & input the height & width to add new videos to the site. Then to display the videos on the page, create a new resource and reference their videos by resource id i.e.

    <br />video one [[~123]]<br />video two [[~123]]<br />


    The video page would use a "video template" template that would handle all the extra loading of extra javascript etc.

    But here’s my question/problem/rub.

    How do I ’wrap’ the static resource in a chunk or snippet or something? There’s no problem referencing the static resources, but each video will have to be wrapped in a javascript that uses the template variables I have created.

    Any thoughts??

    -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
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      If you just need the link to the videos you can use getResources for that, and just link to the id.

      If you on the other hand want to include the actual video code, you will probably need a snippet that includes the content of the static resource. GetResourceField may do that, but it’s also possible that it just fetches the raw content (ie: the file reference), and you’ll need a snippet that uses $resource->getContent instead.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 26503
        • 620 Posts
        I would up creating a snippet for this with a chunk, a TV and an IF instance to pull this off:

        First, I created a boolean TV [[*LoadFlowPlayer]] to indicate if the page in question should load the javascripts [in the head] required to display the videos.
        Second,I created the if instance in the head of the document to only Load the javascript if the LoadFlowPlayer TV is true

        [[!If? &subject=`[[*LoadFlowPlayer]]` &operator=`eq` &operand=`true` &then=`[[$FlowplayerJS]]` ]]


        Third, I created the javascript chunk [[$FlowPlayerJS]] and pasted my javascript in there:

        <script type="text/javascript" src="/assets/flowplayer/flowplayer-3.1.4.min.js"></script>


        Fourth, I setup some system variables to hold some default values for the snippet parameters, since most of the videos are in the same location & of the same size...

        Finally, I created the [[ShowVideo]] snippet:

        
        <?php
        
        	/*
        	[[!ShowVideo? 
        		&path=`_file-name_`  // REQUIRED! include the full path to the file i.e. /_folder_/_sub-folder_/_file-name_
        		&width=`480`  // default, not required
        		&height=`360` // default, not required 
        		&autoplay=`false`  // default, not required
        		&autobuffer=`true`  // default, not required
        		&url=`_repository-url_` // default, not required
        		]]
        	*/
        	
        	 
        	$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
        	$videoid = '';    
        	for ($p = 0; $p < 25; $p++) {
        	   $videoid .= $characters[mt_rand(0, strlen($characters))];
        	}
        	
        	if (!isset($width)){ $width = $modx->getOption('flowplayer_width'); }
        	if (!isset($height)){ $height = $modx->getOption('flowplayer_height'); }
        	if (!isset($autoplay)){ $autoplay = $modx->getOption('flowplayer_autoplay'); }
        	if (!isset($autobuffer)){ $autobuffer = $modx->getOption('flowplayer_autobuffer'); }
        	if (!isset($url)){ $url = $modx->getOption('amazon_url'); }
        	
        	if (isset($path)){
        		$video = 'http://' . $url  . '/' . $path; 
        		$divstyle = 'margin:0 auto;width:'.$width.'px;height:'.$height.'px';
        		$hrefstyle = 'style="display:block;width:'.$width.'px;height:'.$height.'px;"';
        		
        		$flowplayer = '<div class="video-player" style="'.$divstyle.'"><a  href="'.$video.'"  '.$hrefstyle.' id="' . $videoid . '"></a></div>';
        		$javascript = '<script>	flowplayer("' . $videoid . '", "/assets/flowplayer/flowplayer-3.1.5.swf",  {clip: {autoPlay:' . $autoplay . ',autoBuffering:' . $autobuffer . '}});</script>';
        		
        		echo $flowplayer; 
        		echo $javascript;
        	
        	}else{
        		echo "error - no video file specified!";
        	}
        



        So it works quite well and allows me to post multiple videos per page & best of all the user only really needs to learn the minimum tag to insert, which is: [[!ShowVideo? &path=`filename` ]]


        The php probably could use some love, but what I still have questions about is my method of retrieving the system variables
        $modx->getOption('flowplayer_width');


        Is there a better/sexier way to do that? it just feels inefficient...

        -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
          • 26503
          • 620 Posts
          Hi Mark;

          I forgot to mention, the files are located in an Amazon bucket & not local to the modx instance....

          What I came up with does work, but thanks for the suggestion though,

          -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
            • 18373 ☆ A M B ☆
            • 3,141 Posts
            I always use getOption. You should also be able to do just $scriptProperties[’option’] but I prefer using the method.

            Good to hear you got it solved smiley
              Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

              Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.