• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Check for usernames (Template Level)

Scheduled Pinned Locked Moved Unsolved Technical Support
4 Posts 2 Posters 161 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Teemberland
    wrote on last edited by
    #1

    Hi there, I'm wondering if there is a way to check for usernames on the template level? We are currently using javascript to find and replace portion of each username to display certain image. This works, but there are times that it looks tacky when there is a delay on page load. When there is a delay, you would see the text before it gets replaced by js.

    I hope this make sense.

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #2

    Can you share a screenshot of what the end result is right now?

    T 1 Reply Last reply
    0
  • T Offline
    T Offline
    Teemberland
    replied to <baris> on last edited by
    #3

    @baris Screenshot 2022-10-28 at 11-09-23 sdod_pat1 is back!.png

    This is how it works currently. We are matching specific string in usernames (in this case we are matching '_PSN') and replacing that with the PSN icon. This works fine, but as I mentioned in my OP, it looks tacky when there is a delay. It will flash the username with _PSN first then replace it with the image.

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by baris
    #4

    In that case you could use a server side hook filter:topic.getPosts this hook receives the posts being loaded in the posts variable. In that hook you can check the username and add a new property to the post.user object like platformIcons. Here is some sample code for the server side hook

    myPlugin.filterTopicGetPosts = (hookData) => {
       hookData.posts.forEach((post) => {
             if (post && post.user) {
                 post.user.platformIcons = [];
                 if (post.user.username.endsWith('_PSN')) {
                   post.user.truncatedUsername = post.user.username.replace(/_PSN$/, '');
                   post.user.platformIcons.push({ url: '', image: ''});
                 }
                 // check other platforms like above
             }
       });
       return hookData;
    };
    

    Once you have the platformIcons populated you can just use it in your custom theme in the topic/post.tpl. You can use the truncatedUsername as well if you don't want to see _PSN in the username.

    1 Reply Last reply
    1
  • julianJ julian moved this topic from NodeBB Development on

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development