We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42492
    • 31 Posts
    I have a snippet called ArchivedNews that looks like this:
    <?php
    $c = $modx->newQuery('modDocument');
    $c->where(array(
    	'published' => '1',
    	'isfolder' => '0',
    	'context_key' => 'news',
    ));
    $c->sortby('publishedon', 'DESC');
    $c->limit(20, 10);
    $docs = $modx->getIterator('modDocument', $c, 0);
    
    $output = '<ul>';
    foreach($docs as $doc) {
    	$properties = $doc->toArray();
    	$output .= $modx->getChunk('DepartmentalNewsListItem', $properties);
    }
    $output .= '</ul>';
    return $output;


    The chunk DepartmentalNewsListItem:
    <li style="list-style-type:disc; color:#c93; list-style-position: inside">
    <a href="[[!~[[+id]]]]">
    [[+pagetitle]]
    </a>
    </li>


    Here is where I am calling ArchivedNews within my sites main Template:
    ...
    <div id="news">
    <h4 class="title">News Resources</h4>
    <!-- Other news related links -->
    [[Wayfinder? &contexts=`web` &startId=`47` &outerTpl=`NewsResourcesTpl` &cacheResults=`0`]]
    <!-- List of archived news -->
    [[!ArchivedNews]]
    </div>
    [[*content]]
    
    	</div>
    
    	[[$StatFooter]]
    
    	[[$StatGoogleAnalytics]]
    
    </div>
    ...


    Basically, this archived news sidebar floats on the side of the template. I am having some very strange behavior though that I think might be cache related. When I navigate to my home page, I can see the archived news sidebar with all of the links spit out by the snippet. However, the href of all those links are completely empty, and thus just refresh the current page...only when I click on one of the links do the hrefs update to the appropriate page like it is supposed to.

    For example, on loading the home page the hrefs look like this:
    <a href>...</a>
    <a href>...</a>
    <a href>...</a>
    ...

    And after I click one of the links they look like this:
    <a href="archived1.html">...</a>
    <a href="archived2.html">...</a>
    <a href="archived3.html">...</a>

    Can anyone offer any help as to what is causing this?

    Thank you.

    This question has been answered by multiple community members. See the first response.

      • 42562
      • 1,145 Posts
      Sounds like a caching problem. From a guess, I'd say remove the exclamation mark in <a href="[[!~[[+id]]]]"> and then clear the Site's cache.
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
        • 42492
        • 31 Posts
        Quote from: donshakespeare at Mar 04, 2013, 04:33 PM
        Sounds like a caching problem. From a guess, I'd say remove the exclamation mark in <a href="[[!~[[+id]]]]"> and then clear the Site's cache.</a>

        Thanks for the reply. I tried this but the same behavior remains...
          • 42492
          • 31 Posts
          I have some more information that may provide a clue as to what is wrong. I found that when I first visit the home page all the links' href attributes are empty like so:

          <a href>...</a>
          <a href>...</a>
          <a href>...</a>

          And when I click one the page "refreshes" and they are fixed:

          <a href="article1.html">...</a>
          <a href="article2.html">...</a>
          <a href="article3.html">...</a>

          And then when I click on of those it fetches the appropriate article but breaks all the links again:

          <a href>...</a>
          <a href>...</a>
          <a href>...</a>

          And so on and so on......
            • 39404
            • 175 Posts
            stalemate resolution associate Reply #5, 13 years, 7 months ago
            Hi csauer,

            Just as a wild guess, try changing

            <a href="[[!~[[+id]]]]">

            to
            <a href="[[!~[[*id]]]]">


            (in other words, change the +id to *id). I found mention of it here:
            http://rtfm.modx.com/display/revolution20/Commonly+Used+Template+Tags

            Regards,
            Tom
              • 3186 ☆ A M B ☆
              • 279 Posts
              @Tom;
              No he should use [[+id]] and not [[*id]].. Because *id is the current resource and +id is the placeholder in his $doc->toArray() array.

              I think you should just do [[~[[+id]]]] .. so leave the ! out.. because the chunk is parsed fresh from the source it will not be cached
                MODX Ambassador (NL) & Professional MODX developer
                Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
                MODX e-commerce solution SimpleCart
                • 3749
                • 24,544 Posts
                I'm with Bert. Using ! will delay the processing of the tag, which you don't want here. The getChunk() call will replace the id tag with the cached version of the tag rather than the ID and since no placeholder is set, MODX will later just strip out that tag.
                  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
                  • 42492
                  • 31 Posts
                  Quote from: bertoost at Mar 07, 2013, 12:32 AM
                  @Tom;
                  I think you should just do [[~[[+id]]]] .. so leave the ! out.. because the chunk is parsed fresh from the source it will not be cached

                  The problem still persists. Here is the order I am calling everything in:
                  [[$NewsResources]] //on my featured news page
                  
                  [[!ArchivedNews]] //within the NewsResources chunk
                  
                  /* <All within the ArchivedNews snippet> */
                  $c = $modx->newQuery('modDocument',null);
                  ...
                  $docs = $modx->getIterator('modDocument', $c);
                  ...
                  $output .= $modx->getChunk('DepartmentalNewsListItem', $properties);
                  /* </All within the ArchivedNews snippet> */
                  
                  //And then the updated DepartmentalNewsListItem
                  [[~[[+id]]]]
                  


                  My featured news page includes the NewsRecources chunk, which calls the ArchivedNews snippet, which in turn makes calls to modx services to retrieve archived news information and display each in a DepartmentalNewsListItem chunk.

                  I only included lines of text from the ArchivedNews snippet that I believe could pulling from the cache.

                  [EDIT]
                  Here is the NewsResources chunk:
                  <div id="news">
                    <h4 class="title">News Resources</h4>
                    <!--[[!Wayfinder? &contexts=`web` &startId=`47` &outerTpl=`NewsResourcesTpl`]] -->
                    [[!ArchivedNews]]
                  </div>
                  
                    • 42492
                    • 31 Posts
                    Can anyone help with this?
                      • 3749
                      • 24,544 Posts
                      Try using getCollection() instead of getIterator(). I've had trouble with getIterator() and nesting, since getIterator() doesn't actually get the data until it's needed and if it's not needed in the snippet with the getIterator() call, it may not show up at all.

                      In general, though, I think I would try to redesign this so that you don't have to nest things so deeply. It appears that you have a resource field tag inside a link tag inside a chunk inside a snippet inside a chunk. I try not to ever get more than two, or occasionally three levels deep.
                        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