We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40088
    • 708 Posts
    Revo 2.6.2

    I'm trying to use Profile to grab an extended user field (created with ClassExtender) named "screenName" in a Resource Template (not a Chunk).

    The "screenName" should reflect the user who created the Resource and not the signed-in user.
    [[!If?
        &subject=`[[+screenName]]`
        &operator=`empty`
        &then=``
        &else=`Name: <a href="[[~20? &author=`[[*createdby]]`]]" rel="author">
        [[!Profile?
            &user=`[[+createdby]]`
            &useExtended=`1`
        ]]
    [[*createdby:userinfo=`extended.screenName`]]</a>

    No output.

    This question has been answered by BobRay. See the first response.

    [ed. note: todd.b last edited this post 6 years ago.]
      Todd
    • discuss.answer
      • 3749
      • 24,544 Posts
      Try putting this above your code:

      [[!setUserPlaceholders? &userId=`[[*createdby`]]


      Then just use this for the screen name:

      [[+screenName]]
        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
        • 40088
        • 708 Posts
        Thanks Bob, but it still returns the signed-in user, not the author.
          Todd
          • 3749
          • 24,544 Posts
          I can't explain that. Are you sure you used &userId and not &userID?
            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
            • 40088
            • 708 Posts
            Bob, I got it sorted out (I think).

            There was a typo in setUser. Here's what works,
            [[!setUserPlaceholders? &userId=`[[*createdby]]`]]

            Thank you.

            By the way, when using your example in a Chunk vs. a Template (which works fine) the same problem happens with the name of the signed-in user showing instead of the author.

            Why do Chunks and Templates behave differently with regard to this?

            [ed. note: todd.b last edited this post 6 years ago.]
              Todd
              • 3749
              • 24,544 Posts
              If it's a chunk pulled in with getResources or something similar, you'd have to use this:

              [[+createdby]]


              and hope that the snippet sets that placeholder correctly.

              If it's pulled in from a regular chunk tag, try this:

              [[!+createdby]]


              I'm not sure it will work.

                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
                • 40088
                • 708 Posts
                Thanks, Bob.

                I fixed it, though I still don't understand why it works. The whole when-to-use "cached" or "uncached" is still a mystery to me.

                In the template I changed
                [[pdoResources?
                &tpl=`Results`
                ...

                to
                [[!pdoResources?
                &tpl=`Results`
                ...

                And the "Results" tpl contains:
                [[!setUserPlaceholders? &userId=`[[+createdby]]`]][[+screenName]]

                works as expected. [ed. note: todd.b last edited this post 6 years ago.]
                  Todd