We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43264
    • 3 Posts
    Hi there, i'm not sure this is the right place to post this thread...
    Anyway i'm developing a one page site on modx revo 2.2.5, using modernizr, history.js, json2 and several jquery plugins: i have a single template, this template loads via javascript a plain html file (content.html) that contains all the content for the various sections of the site, now, i need content.html to be able to dinamically load content from my modx documents.
    Tried something like this:
    [[getResourceField? &id=`46` &field=`content`]]

    i get no errors on firebug but the output on the page is the plain code: [[getResourceField? &id=`46` &field=`content`]] .
    content.html file is located in "assets/templates/mytemplate/content.html", anyway it seems that modx has no access to that file, any suggestions?

    p.s. sorry for my bad english...
      • 40045
      • 534 Posts
      modx has probably access to that file, but the snipet doesnt get processed, so that's why you get the snippet tag as the output. Try to create a resource inside the manager with an empty template and give it an alias, for example "ajax-content".

      Don't know if you need it dynamically, but sound like, so here's what I would do (see comments for detail):

      Create a new snippet, let's call it [[getContent]]

      // get all request parameters in an array and eliminate $_COOKIE from "normal" $_REQUEST superglobal
      // values in $_POST with the same key will override the ones from $_GET!
      $_REQUEST = array_merge($_GET, $_POST);
      $settings = filter_var_array($_REQUEST, FILTER_SANITIZE_STRING); // clean request params from unwanted, harmful stuff
      unset($settings['q']); // remove the modx query param from the $settings array
      
      // then just run the snippet via jQuery for example with $('#content').load('http://www.domain.tld/ajax-content.html?id=46');
      return $modx->runSnippet('getResourceField', array('id' => $id, 'field' => 'content'));
      
        • 43264
        • 3 Posts
        Hi exside,
        thank you!
        Your solution works pretty well, but i still have a problem: running the snippet via jQuery in content.html, i'm adding the html from the modx document into the DOM, but, for SEO reasons, i need it also in the "actual source of the page"...
        I think i need something similar to a "chunk" to "include" the html into content.html, to do this i need to find a way to get the snippet processed by modx...
        Perhaps i could turn content.html into a php file and try to use the modx object($modx) to retrieve the documents i need?
        Any suggestions?
          • 40045
          • 534 Posts
          or just replace getResourceField with getResources and use a tpl chunk there?
            • 43264
            • 3 Posts
            Hi there, sorry for my late reply, i found out that to achieve what i want it was easier than i thought it would be... Using your first solution, the only thing to do is to call the content inside the template with the [[*content]] tag!
            Thank you again for your support!