We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28432
    • 372 Posts
    Hello, i'm trying to make a new extra that will needed to be always call uncached. I would like to understand what's happen to the content inside this snippet.
    For example if i call pagetitle cached inside my uncached snippet :
    [[!myFuturExtraUncached? output=`[[pagetitle]]`]]

    Is pagetitle will be cached or uncached ?
      • 3749
      • 24,544 Posts
      Uh, neither. Since you haven't use * or + in the tag, the snippet will get the full string, tag and all.

      With [[*pagetitle]], I believe it will get the title of the current page (so, essentially uncached). With [[+pagetitle]] it will depend on whether and how the placeholder is set.

      If you're getting a field of the current resource, though, it will be faster and more efficient not to make MODX parse that part of the tag and just do this in the snippet:

      $pTitle = $modx->resource->get('pagetitle');


      All the resource's fields are already in an array for the snippet to use, whether you use them or not, so doing it that way is very fast.






        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
        • 28432
        • 372 Posts
        Excuse me Bob, i forgot * or + in my example.
        My snippet will just return what's inside the output script property. A lot of thing have to be possible inside the output script property.

        [[!myFuturExtraUncached? output=`[[*pagetitle]]`]]

        [[!myFuturExtraUncached? output=`
            <div class="aClassName">[[*aTV]]</div>
        `]]

        [[!myFuturExtraUncached? output=`
            <div class="aClassName">[[getResources? &parents=`[[*id]]` &tpl=`myRowTpl`]]
        `]]


        [[!myFuturExtraUncached? output=`
            <div class="aClassName">
                <ul>
                      [[getImageList? &tvname=`myMIGXtv` &tpl=`thumbTpl`]]
                </ul>
            </div>
        `]]
          • 3749
          • 24,544 Posts
          Maybe you have something else in mind to do in the snippet, but all of those examples will work fine without a snippet:

          [[*pagetitle]]
          
          <div class="aClassName">[[*aTV]]</div>
          
          <div class="aClassName">[[getResources? &parents=`[[*id]]` &tpl=`myRowTpl`]]
          
          <div class="aClassName">
              <ul>
                  [[getImageList? &tvname=`myMIGXtv` &tpl=`thumbTpl`]]
             </ul>
          </div>
          


            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
            • 28432
            • 372 Posts
            Yes Bob, sorry to haven't be clear before. The snippet will detect device like mobile, tablet and computer on server side. So with properties you can easily show or hide what's in the output property. It' why i need to know if the call inside the output script property will respect cache system.
            [[!deviceDetection? &computer=`1` &tablet=`1` &mobile=`0` &output=`
                something call cached or uncashed you want to be show on tablet and computer and hide on mobile (phone)
            `]]
              • 3749
              • 24,544 Posts
              Ah, I get it. Are you trying to avoid media queries in your CSS for some reason?

              For example:

              <div class="aClassName">
                  <ul>
                      [[getImageList? &tvname=`myMIGXtv` &tpl=`thumbTpl`]]
                  </ul>
              </div>



              CSS file:

              @media only screen and (max-width: 320px) {
                .someClassName {
                   display:none; 
                }
              
                .someOtherClassName {
                   display:block;
                }
              }


              If you do it this way, it will be infinitely faster than having your snippet run, parse its parameters, and respond to the screen-size over and over. It's also a lot easier, imo.

              You can use class names like "Phone", "Tablet", "Notebook", "Desktop", or even class names like "PhoneAndTablet", "PhoneOnly", "TabletLandscape", "TabletPortrait", "TabletOrSmaller" "NoteBookOrBigger", etc.


                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
                • 28432
                • 372 Posts
                No, the snippet will detect device on server side, so it will return or not return the code in output property.

                For doing it in CSS it's pretty simple with Bootstrap for example. But in this way the code stay inside the page and will be just hide by CSS.