We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40122
    • 330 Posts
    I am using getResources to display blog entries. For each entry I want to display the name of the user who created the resource.

    I can retrieve their ID using placeholder [[*createdby]] but I don't know how to get their name.

    Does anyone know how to do this?
      • 42562
      • 1,145 Posts
      https://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-(output-modifiers)
      There is an input/output modifier for that: userinfo

      [[*createdby:userinfo=`username`]]

      [[*createdby:userinfo=`fullname`]]

      etc

      A little snippet might be faster though, who knows!!
        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.
        • 3749
        • 24,544 Posts
        A dedicated snippet will be much faster because the output modifier won't have to be parsed, and the user object won't need to be retrieved. I assume that your tag is in a Tpl chunk, since you're using getResources. You need to user + for the createdby tag, not *. Using * will get you the user who created the page with the getResources tag, not the blog post.

        This is a particularly fast way to do it:

        [[!GetCreatedbyFullname? &createdby=[[+createdby]] ]]


        /* GetCreatedbyFullname snippet */
        
        $userId = $modx->getOption('createdby', $scriptProperties);
        $query = $modx->newQuery('modUserProfile', array('internalKey' => $userId);
        $query->select('fullname');
        $output =  $modx->getValue($query->prepare());
        
        /*  optional - use the username as a backup if the full name is empty */
        if (empty($output)) {
            $query = $modx->newQuery('modUser', $userId);
            $query->select('username');
            $output = $modx->getValue($query->prepare());
        }
        /* end of optional section */
        
        return $output;
        
        


        The optional section will slow things down by a few milliseconds, but it won't execute if the full name is found. If you don't use the optional section, make sure every user has a full name in their profile. [ed. note: BobRay last edited this post 11 years, 1 month ago.]
          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