We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53247
    • 14 Posts
    Greetings. What would be the best way to either include or exclude chunk content within a given resource based on user credentials? So, in other words -- if a User Group (Group A) allows access to a resource that includes a certain Chunk (Chunk X), but I only want Chunk X to show up for a subset of users in Group A, how do I lock down Chunk X so that it will only show up for the subset of users in Group A? Resource Groups allow you to specify which resources are part of a group, but Resource Groups do not seem to allow you to get more granular than that and include / exclude particular chunks that may be part of a given resource. MODx CLEARLY offers a way to accomplish what I am looking to do here, but I am still trying to work through the complexities of credentialing in this framework and -- even though I have now been able to successfully set up a user who can access the front-end via the Login package -- I remain unsure on how to restrict access at the level of a chunk. Thanks.
      • 3749
      • 24,544 Posts
      There may be a way to do it with permissions, but I would use a custom snippet and put the subset of users into another group called GroupX (users can be in more than one group).

      Put this where you want the content to appear:

      [[!GroupXOnly]]


      Then create a snippet called GroupXOnly with this code:

      if ($modx->user->isMember('GroupX')) {
         return $modx->getChunk('ChunkX');
      } else {
      
         /* delete the two lines below that you don't need */
         return ''; // return nothing
         return "You can not see this content"; // return a message
         return $modx->getChunk('ChunkA'); // return another chunk
         
      }
        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
        • 53247
        • 14 Posts
        Bob. Thank you very much for that suggestion. I will give that a whirl and see if it works. I am trying to build out a Developer Portal. Visitors to the portal will need login credentials. The portal will have a bunch of 'core' content that will be available to all visitors. However, I will need a way to structure things so that other bits of content are only visible to specific sets of visitors. This is the general challenge that is facing me.