We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15566
    • 73 Posts
    Is there a way to not load the template using the API? Because the template gets called higher up I am not sure I can, but any help would be appreciated.

    The reason for this would be... a direct url to a page would load everything but an AJAX call would only get the content, something like:

    <?php
    if($_REQUEST['ajax']){
    // load [*content*]
    }
    else{
    // continue full load with template
    }
    ?>
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You can do that using the jQuery load() function; it allows you to specify the HTML container (such as a div) that you want to use. See the section on "loading page fragments" here http://api.jquery.com/load/
        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
        • 15566
        • 73 Posts
        Thanks Susan. I know how to do the jquery part, but the MODx part I am unsure about. I'll try and explain it a bit better...

        If a visitor visits www.mydomain.com/about-us.html they see the full page with template. If they arrive at www.mydomain.com/index.html and click the about us link it loads the about-us.html page into a div (using the $ load function) but a snippet on that page knows from an identifier of some kind (such as $_REQUEST['ajax'] ) not to load the whole template, but just the content part on the request. So (ignoring the JQuery part) is it possible to allocate a template to a page but on calling that page can the template be disregarded from within a snippet?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          No.
            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
            • 15566
            • 73 Posts
            :)
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Your AJAX load() can specify the element that you want inserted into the div. For example, if you want the main content area, just specify the div (or section or whatever) you have the [*content*] tags in.
              $('#result').load('about-us.html #main');

              Now the whole page will be returned, but the load() function will pick out the content in the #main div or section to load into your #result div or section. The rest of the page will be discarded.
                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
                • 15566
                • 73 Posts
                Ah, now that is something I haven't done before. I will try that. So my question was a JQuery one after all!

                Thanks for your help.