We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I think I see what you're saying. Parsing nested tags is an immensely complex task and I don't claim to be an expert in the process.

    Generally tags are processed from top to bottom and from inside to outside, and there are multiple passes. In each pass, MODX tries to replace any unprocessed tags. When the placeholder for a placeholder tag is not set on a given pass, MODX leaves it alone so it can be replaced in a future pass (when snippet processed in a future pass may have set it). There is also the assumption that when all the passes are finished, any unprocessed tags will be removed. I don't see how it could behave differently and be at all reliable, since it has limited information about the order in which you want the tags processed.

    In this case, I think the ultimate fault belongs to the Register snippet, which should set that placeholder to an empty string when there is no user error. It's somewhat unfair to blame MODX when you are using the value of a placeholder set in one add-on in another add-on you are writing.

    The MTOG example should be definitely be called uncached if the results may vary from page-load to page-load.

    Most people don't mind having an occasional set of empty HTML tags, but you can pretty easily get around this either by using and output modifier (which I think will force the placeholder to be evaluated) or with something like one of the following (I think the second would be a little faster, but I'm not sure):

    Option1:

    [[WrapNotEmpty?
        &beginHtml=`<br /><span class="error">`
        &value=`error.username`
        &endHtml=`</span>`
    ]]


    <?php
    /* WrapNotEmpty snippet */
    $val = $modx->getPlaceholder($scriptProperties['value'])
    return $val? '' : $scriptProperties['beginHtml'] . $val . $scriptProperties['endHtml'];
    


    Option2:

    [[WrapNotEmpty?
        &beginHtml=`<br /><span class="error">`
        &value=`[[+error.username]]`
        &endHtml=`</span>`
    ]]


    <?php
    /* WrapNotEmpty snippet */
    
    $val = $scriptProperties['value']
    if (empty($val) || (strpos($value, '[[') !== false)) {
      return '';
    }
    return $scriptProperties['beginHtml'] . $val . $scriptProperties['endHtml'];
    







      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