We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1235
    • 2 Posts
    Hello Everyone, I have an issue with parse chunk not parsing the [[~[[id]]]] links within my chunks in ModX Revolution 2.0.7.

    I am trying to use a modx chunk in a php file that is external to modx. I have used the following code to connect to the modx api from an external file:
    <?php 
    //modx object - test
    require_once 'manager/config.core.php';
    require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
    require_once MODX_CORE_PATH.'model/modx/modx.class.php';
    $modx = new modX();
    $modx->initialize('web');
    //tim's code:
    define('MODX_SITE_BASE_URL', 'http://my website here.co.uk/');
    // The MODx document we are going to pretend to be
    define('MODX_DOCUMENT_IDENTIFIER', 15);
    // Some defines used by the modx API
    define('MODX_API_MODE', true);
    define('MODX_SITE_URL', (!isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'off' ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].MODX_SITE_BASE_URL);
    // Run the MODx config and get site settings
    require(MODX_MANAGER_PATH.'/../index.php');
    $modx->getSettings();
    // Set the docid (most sensibly to the MODx weblink to here) and get the MODx document object
    $modx->documentObject = $modx->getDocumentObject('id', MODX_DOCUMENT_IDENTIFIER); 
    $modx->documentIdentifier = MODX_DOCUMENT_IDENTIFIER;
    // Set the base URL for any MODx snippets
    $modx->config['base_url'] = MODX_SITE_BASE_URL;
    //END Tim's code
    ?>
    



    The chunk itself (named ’foot’) looks like this:
    <a href="[[~[[1]]]]">Home</a> | <a href="[[~[[2]]]]">About</a> | <a href="[[~[[3]]]]">Contacts</a> | <a href="[[~[[4]]]]">Public Courses</a> | <a href="[[~[[5]]]]">Testimonials</a> | <a href="[[~[[61]]]]">Book Here</a> | <a href="[[~[[7]]]]">Terms and Conditions</a> | <a href="[[~[[8]]]]">Privacy Policy</a>
    


    And have used the following getChunk function to get the chunk:
    echo $modx->getChunk('foot',array());
    



    The corresponding code output from the getChunk function looks like this (Note: The URL’s have not been processed)
    <a href="">Home</a> | <a href="">About</a> | <a href="">Contacts</a> | <a href="">Public Courses</a> | <a href="">Testimonials</a> | <a href="">Book Here</a> | <a href="">Terms and Conditions</a> | <a href="">Privacy Policy</a>
    

    [[~[[1]]]] should return the url to the resource 1.

    I have tried using the parsechunk function to fix it but have had no joy. I have also done a fair amount of searching and have so far been unsuccessful.


    I must be missing a function call or have the procedure of managing chunks externally completely wrong. I would really appreciate it if any of you could resolve this for me. huh
      • 3749
      • 24,544 Posts
      Most of your code is Evolution code, so most of it isn’t working.

      You can use getChunk() to get the chunk and chunk->process() to parse it, but I don’t understand what you’re trying to do well enough to give more detailed advice. Are you intending the alter the MODx db in the process or do you just want output? If you could be clearer about exactly what you want to do and why, there might be a much simpler way.

      You’ll want to use this to set the system settings:

      $modx->setOption($settingName, $value);


      I don’t think you’ll need any defines and I think loading index.php will overwrite your changes (you shouldn’t need it).

      $documentObject and $documentIdentifier are deprecated and I don’t think they’d have a value anyway since there is no current document unless you create one:

      $fields = array (
      ’pagetitle’=>’something’,
      ’id’ = 15,
      ’content’ = ’some content’,
      );
      $modx->resource = $modx(’newObject(’modResource’, $fields);

      See this page: http://bobsguides.com/revolution-objects.html

      Just setting the system settings and calling $chunk = getChunk() and $chunk->process() *might* do what you want, though I’m pretty hazy on what you want to do. wink
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 1235
        • 2 Posts
        After hours on this, the error was simple,

        this:
        [[~[[2]]]]


        should have been this:
        [[~2]]


        If I keep all the other code the same, it works. Even though it uses evolution functions. I have tried chaning things over to Revolutions functions but it broke everything. Oh well, if it aint broke don’t fix it!

        Thank you for your help though. Your response was well thought out so thanks for your time.
          • 3749
          • 24,544 Posts
          Just be aware that the deprecated methods will be removed at some point, so upgrading MODx may break things.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting