We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3677
    • 130 Posts
    I am sure this is a caching issue, but not sure how to fix it.

    This is going to be a pain to describe...hopefully someone can follow along.

    In a template I am calling a tv which then includes an external chunk but I'll skip that and go straight to the chunk content...

    [[!getFormQuestion? &id=`1` &qType=`radio`]]
    [[!getFormQuestion? &id=`2` &qType=`radio`]]
    


    So this is an uncached snippet call that I'd like to run back to back with different properties.

    Snippet Details:
    <?php
    
    //Setting the snippet properties in an array so I can pass it to the html code chunk
    $properties = array(
            'id' => $id,        
    );
    
    switch ($qType)
    {
        case 'radio':
            $code = $modx->getChunk('formRadioQuestion',$properties);
            
            //added the print_r so I could see the array property values during debug
            $output = print_r($properties) . $code;
            return $output;  
            break;
    }
    
    ?>


    I'm simplifying formRadioQuestions code chunk to display the problem..

    <div id="Question[[+id]]">
         <p>QuestionID is set to: [[+id]]</p>
    </div>


    So the first snippet call works as expected and sets the placeholder id as 1 which produces this output:
    Array ( [id] => 1 ) 1
    QuestionID is set to 1

    and the source code:
    <div id="Question1">
         <p>QuestionID is set to 1</p>
    </div>
    


    Now the next snippet call is where I am getting cached values.
    Snippet call:
    [[!getFormQuestion? &id=`2` &qType=`radio`]]

    produces this output:
    Array ( [id] => 2 ) 1
    QuestionID is set to 1

    and the source code:
    <div id="Question1">
         <p>QuestionID is set to: 1</p>
    </div>


    so this call is in fact passing the right property value (id=2)
    $code = $modx->getChunk('formRadioQuestion',$properties);


    but...
    Once the actual code chunk is processed, it is using a cached value for the placeholder
    [[+id]]

    SO I tried adding
    [[!+id]]
    to prevent any caching there but then the placeholder doesn't contain any value at all.

    Ideas?
      • 22303 MODX Staff
      • 10,725 Posts
      Can you confirm what release of Revolution you are using?
        • 3677
        • 130 Posts
        Sure, 2.1.3.pl
        More info...

        I realized that the getChunk call in the snippet is actually retrieving the contents of the formRadioQuestion chunk from the db first and this is an include statement (another snippet call):

        [[!inc? &file=`[[++assets_path]]chunks/formRadioQuestion.chk`]]


        So that inc is being returned from the snippet back to the original modx call and then parsed again?
        Hard to follow for me. Anyway I found that If I put the actual html code in the formRadioQuestion chunk instead of using an include it works as desired. But I pretty much use includes for everything so I don't want to deviate here if I can avoid it.
          • 22303 MODX Staff
          • 10,725 Posts
          That call to inc is what is getting cached; because the tag signature is exactly the same, it simply gets replaced with the values from the first execution. You could work around it by making sure that you add a unique property to the tag string, e.g.
          &foo=`[[+id]]`
          or something
            • 3677
            • 130 Posts
            Sure enough. That does it.

            Thanks!

            -Brian