We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28993
    • 42 Posts
    Hey All,

    I am currently implementing Lightwindow (http://www.stickmanlabs.com/lightwindow/) into my website,
    part of the features I wanted to use was to load a piece of content into the lightbox without the template surrounding it.

    Of course I want my users to easily let a specific url load through Ajax or normal (Unobtrusive behavior) by just specifying the class "lightwindow" on the link, so the url looks something like this "<a class="lightwindow" href="general-terms-and-conditions">General Terms & Conditions</a>".

    I couldn’t find any posts related this / nor any solutions to this, so I created something fast myself and was wondering if this is the right way (or that there is some feature I missed in MODx?).

    I know that alot of librarys provide a "X-Requested-With" in the header so that the destination knows if it is from an Ajax request or not,
    so I created a plugin to handle this on the "OnWebPagePrerender" event from MODx.

    Here is the code of the plugin.
    // Checks if in an Ajax call is made by checking if the value in X-Requested-With is given in the header.
    if (isset($_SERVER['HTTP_X_REQUESTED_WITH']))
    {
      $content = '';
    
      if (isset($modx->documentObject['content']))
        $content = &$modx->documentObject['content'];
    
      // Set the event output
      $modx->documentOutput = $content;
    }
    


    Any feedback on this /or pointing to a place where a same / better solution is provided would be nice.
    If not it might be interesting to implemented this into MODx or make this a plugin? Any naming suggestions? tongue

    Grz,
    Stefan
      • 33992 ☆ A M B ☆
      • 455 Posts
      Goood trick, grin
      I use _ajaX key in my ajax queries, we can also check for a certain query and do this.

      Thanks
        God loves me. 【ツ】


        MODX.ir (Persian Support)

        Boplo.ir/modx/ (Persian)
        • 22303 MODX Staff
        • 10,725 Posts
        Rather than waiting until the end of processing everything in the template (i.e. OnWebPagePrerender), wouldn’t this make more sense executed OnLoadWebDocument:
        <?php
        // Checks if in an Ajax call is made by checking if the value in X-Requested-With is given in the header.
        if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
          $modx->documentContent = '[*content*]';
        }
        ?>