We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37619
    • 79 Posts
    Using MODX 2.2.14

    Hi everyone,

    I'm processing a chunk via the API using AJAX. It's pulling all the data as it's supposed to, however, the snippet being called in that chunk isn't processing. Also, only some conditional statement will not work if false.

    AJAX File
    <?php
    
    // Get Variables
    $project_id = $_POST['project_id'];
    
    // Include MODX
    require_once '../config.core.php';
    require_once MODX_CORE_PATH.'model/modx/modx.class.php';
    $modx = new modX();
    $modx->initialize('web');
    $modx->getService('error','error.modError', '', '');
    
    // UPDATE Project Phase & Status
    $sql = "SELECT * FROM table_name WHERE id=".$project_id;
    
    $query = $modx->query($sql);
    $info = array();
    if($query){
        while($project = $query->fetch(PDO::FETCH_ASSOC)) {
            array_push($info, $project);
            $output .= $modx->getChunk("tpl_project_page",$project);
        }
    }
    
    echo $output;
    


    Chunk: tpl_project_page (simplified)
    <h3>[[+priority:is=`1`:then=`<small><span class="label label-danger">!!!</span></small> `]][[+client_name:ucwords]]</h3>
    
    <p>ERP ID: [[+erp_project_id:empty=`N/A`]]</p>
    <p>Platform: [[+project_platform:empty=`N/A`]]</p>
    <p>Staging Site URL: [[+staging_site_url:empty=`N/A`]]</p>
    <p>Live Site URL: [[+live_site_url:empty=`N/A`]]</p>
    
    <h3>People</h3>
    [[!get_profiles? &project_id=`[[+id]]`]]
    

    In the case above:

    • [[+priority:is=`1`:then=`<small><span class="label label-danger">!!!</span></small> `]] is returning the whole conditional statement, with the html formatted.
    • ERP ID returns [[+erp_project_id:empty=`N/A`]], while all the other ones are returning "N/A" when they're empty.
    • The get_profiles snippet returns [[!get_profiles? &project_id=`51`]].
    *see attachment for output

    Am I doing anything wrong? Or am I missing something?
    Thank you.
      Jean-Marc Buytaert (@jmbuytaert)

      MODX truly is the greatest thing that's ever happened to the Internet.
    • You have nothing here to process the non-cacheable tags. MODX works by allowing each element to process it's own cacheable tags first. Once all cacheable tags have been processed, then another pass is made by the parser (see modResponse::outputContent()) to process the non-cacheable tags. You would need to do this manually since you are not using the MODX request handler.