Fork me on GitHub

Convert uid to username - in template or code?  Bottom

  • I've got the uid passing to a template and was wondering if there was a pnRender tag to convert it to an actual username...or should I just do it before the template and assign it?
  • John,

    You can do it either way (both are similar).

    PHP - $pnRender->assign('uname', pnUserGetVar('uname', $uid));
    template -

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Ah...very nice! Thanks Mark...
  • Where is the best place to go for docs on pnRender tags...straight to the Smarty help? ...or is there something more nuke-specific?
  • In addition to the Smarty docs there's these which are linked from docs.postnuke.com. This is the documentation for .750 but will be updated shortly for .760 as there are some new and a few updated tags.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • IMO it's best to pass the username to the template as a parameter and reference it by something obvious like

    I keep forgetting in the things I code that the aim of templating is seperation of the display stuff and the code, and so I personally think that the less 'code' in templates, the better.

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • HammerHead

    IMO it's best to pass the username to the template as a parameter and reference it by something obvious like

    I keep forgetting in the things I code that the aim of templating is seperation of the display stuff and the code, and so I personally think that the less 'code' in templates, the better.


    It depends... The trade off is that you're deciding that it's the username that should be displayed here. What if the site admin would prefer the real name displayed?

    We can't use the pnusergetvar plugin with only the username. The compromise is to assign both your choice (as the developer) and the user id.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Personally I'd assign most of the variables I used in the function to the template. If a designer wants to radically redesign the template they'll want all the variables available to use.

    Obviously, in an ideal situation, where you knew exactly what you wanted you wouldn't do this.

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • Luckily, in this case, all I need is the username, so it's not as complex a decision... :) Assigned to the template they will be...
  • I've found modules/pnRender/plugins to be a veritable treasure trove of functionality... mind the ones marked legacy.

    What i noticed even earlier today, is that there is a very slight performance hit for using smarty/pnRender over assigning the variable... like .02-3 secs every 4 out of 10 or so. Negligable, but it'll add up.

    Decisions decisions...

    --
    Under Construction!
  • While there is the slight performance hit this is only when the template is executed. Don't forget that Smarty is designed as a caching template engine.

    Running .760 on my site i've got xanthia's full page caching enabled and have not found anything (for my small site) that i've needed to exclude from caching. There's a little bit of additional code in .760's xanthia (and now .750b) that checks for the post array having some content (a form submission) and will clear the cache for that module. In .760 (but not .750b) the logic also clears the cache for any hooked modules.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Quote

    Running .760 on my site i've got xanthia's full page caching enabled and have not found anything (for my small site) that i've needed to exclude from caching.


    Although it is possible to run something as dynamic as a forum using Xanthia's full page cache (I did this over at www.eurojamlive.org) you'll find that the 'latest post' indicators on PNphpBB are not refreshed as the index page of PNphpBB never receives POST content. Instead, you'll need to wait for the cache to expire.

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide

This list is based on users active over the last 60 minutes.