We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17306
    • 2 Posts
    So my problem is I have a Snippet I created for a website and it needs to be able to have two different sizes; the default size for video and the ’small’ size for the same video on a different page.

    <?php
    
    // URL of Video
    // Default: 
    // To change, use vid
    // [[NewsVideo?vid=7V5njXJt3H8]]
    $vidURL = '';
    
    // Width of Video
    // Default: 640
    // To change, use LIn_width
    // [[NewsVideo?LIn_width=853]]
    $vidWidth = 640;
    
    // Height of Video
    // Default: 385
    // To change, use LIn_height
    // [[NewsVideo?LIn_height=505]]
    $vidHeight = 385;
    
    // Use snippet call defined variables if set
    $vidURL = (isset($vid))? $vid : $vidURL ;
    $vidWidth = (isset($LIn_width))? $LIn_width : $vidWidth ;
    $vidHeight = (isset($LIn_height))? $LIn_height : $vidHeight ;
    
    // Initialize output
    $output = '';
    
    // Get Page
    $curPage = $_GET['q'];
    // Check Page, if not new page, Resize to 285 x 171 pixels
    if($curPage == '') {
     $vidWidth = 285;
     $vidHeight = 171;
    }
    
    // Output
    if(strlen($vidURL > 0)) {
    $output .= '<object width="' . $vidWidth . '" height="' . $vidHeight . '"><param name="movie" value="http://www.youtube.com/v/' . $vidURL . '&hl=en_US&fs=1?rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $vidURL . '&hl=en_US&fs=1?rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' . $vidWidth . '" height="' . $vidHeight . '"></embed></object>';
    } else {
     $output .= '<p><b>Video Not Found</b></p>';
    }
    
    return $output;
    ?>
    


    I’m not a web expert, so if methods here are wrong you can correct if you wish (and I’ll probably fix them), but that’s not why I’m here.

    The $_GET function I’m using works fine only after I save the snippet. As soon as I edit the resource and save it (even if not changes were made), the get function won’t work. I know this because I had the output also printing the array of print_r($_GET) and just printing $curPage and they would both show blank (or as unbound). As soon as I went in, edited the snippet (even if no changes) and saved it, reloaded the page, everything worked like normal.

    My URL’s are set up as semi-friendly, so /?q=xxxxxx where xxxxxx is the longtitle of the page (in my case, /?q=race-update-73110 is the page I have been testing on.

    I’m just confused as to why MODx seems to not be passing (or able to retrieve) the ’q’ variable from the URL after I update a resource (even if I ctrl + refresh, go to other pages and come back, etc)

    EDIT:
    // Get Page
    $curPage = $_GET['q'];
    // Check Page, if not new page, Resize to 285 x 171 pixels
    if($curPage == '') {
     $vidWidth = 285;
     $vidHeight = 171;
    }
    

    because the home page is the only page without /?q= in its URL (and the only page the small video is displayed on)

    If there is a way to determine the Parent page (all news stories are stored in the parent ’News’, all press stories are stored in the parent ’Press’ I would love to know how to do that as well, that way I can use the same snippet for both pages (though I guess I could anyways)
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      If your home page is where the small one needs to be displayed, you can determine that in this manner:
      if($modx->documentIdentifier == $modx->config['site_start']) {
          // code here
          ...
      }
      
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 17306
        • 2 Posts
        lifesaver!

        <3 thanks a ton =) that was way easier of a fix to make (and something easy to implement in the future)!
          • 9094
          • 8 Posts
          Hi!

          I have a similar problem with this in modx revolution 2.0.

          The array $_GET don’t is actualized,

          if my url is --> http://myweb.com/index.php?id=33&m=2

          The ouput ot the $_GET is --> http://myweb.com/index.php?id=33&m=1

          And i can retry but the output don’t change, only when i save the snippet again.

          How can i resolve this, please??

          Thanks in advance


            • 22303 MODX Staff
            • 10,725 Posts
            Call your Snippets uncached.
              • 9094
              • 8 Posts
              Thanks for your reply OpenGeek but this don’t resolve the problem:

              This is the code of my snippet call:

              [[!listado_profesionales!]]

              But later, the $_GET dump is different from the actual url

              Any idea?

              Thanks
                • 36592
                • 970 Posts
                [[!listado_profesionales!]]


                You do not need "!" at the end of the call.
                [[!listado_profesionales]]