We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36692
    • 13 Posts
    I'd like to ask this question to make sure I don't "invent" a way to do something that's best done a different way.

    Let's say in a template you want to show the user's display name after login.

    In my login snippet, I set the displayname into session.

    $_SESSION['displayname'] = $obj->get('displayname');


    Option 1: In the template, I can call a snippet that returns the displayname

    Option 2: Somewhere (where would I do this?) call

    $modx->toPlaceholder('displayname', $_SESSION['displayname'],'wms');


    to create a placeholder and then show it in the template with

    [[+wms.displayname]]


    Or is there some better way to do this? Thanks for any help and best practice advice.

      • 22303 MODX Staff
      • 10,725 Posts
      Both options are valid. For option 2, call the Snippet non-cacheable before the placeholder appears in the content, and mark it non-cacheable as well, so the value is not stored in the cacheable output of the Resource.