We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8023
    • 4 Posts
    I’d like to display a specific chunk in my template only when the page is being viewed by an anonymous user.
    I thought the ’isnotloggedin’ output filter would be perfect for this - I just didn’t quite get the hang of it how to use it.

    I tried thins like
    [[$chunkName:isnotloggedin=`output`]]

    or
    [[$chunkName:isnotloggedin:then=`output`]]


    Nothing worked so far. Does anyone have a working an example of the ’isnotloggedin’ or (’isloggedin’ for that matter) output filter?

    Thx,
    David.
      • 22019
      • 390 Posts
      That filter only returns true or false.

      Cackhanded way of doing what you want, hopefully someone will point out a better way:

      [[+modx.user.id:lt=`1`:then=`[[$chunkName]]`]]


      ie if the user is anonymous they will have an effective id of 0.
        Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
        • 3749
        • 24,544 Posts
        You can also install the Personalize snippet through Package Manager, which will let you show one chunk to logged in users and another (possibly empty) chunk to anonymous users.
          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
          • 8023
          • 4 Posts
          Thanks for the quick responses, odeclas and BobRay.

          I prefer odeclas’ suggestion as what I’d like to achieve is to hide the Google Analytics script, if a logged in user (aka an editor) looks at the site.
          Although the code seems reasonable to me and also perfectly in line with the documentation I haven’t been able to get any output from [[+modx.user.id]], no matter if used in the template or within a chunk. I thought the times of web and manager users are gone with Revo?

          And to stick somewhat to the topic: what’s then a practical use of ’:isnotloggedin’?

          - David.
            • 3749
            • 24,544 Posts
            Are you previewing from the Manager? That can throw things off. I think the user ID is 0 in that case.

            Is the front-end user logged in to the current context (e.g., ’web’)?

            I generally try to avoid using the conditional output modifiers except for prototyping, because the parsing required for them makes them slower and less efficient.
              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