an alternative to @name

  • Affected Version
    WoltLab Suite 3.0

    Hello ,

    there are a plugin or something in woltlab to copy the name of a user to a post ? , i know i can use the @ plus the name . My users like to put the name to thanks and a click on the name to have the name in the post would be a good solution .

    we have


    thanks julie,marc, epic32 , epic22 ., admin , modo 1 ...... for the answer

  • I don't know if it helps you.

    Suite Core has a built in user tag which uses the id of an user. [user=1474569][/user] becomes marcbelgique.

    The other way is creating a link with an own link text. <a href="">Fighter456</a> becomes Fighter456.

    For both solutions it should be possible to create a box containing the codes for a visited user profile for simple copy and paste.

  • Thanks for your reply , but i need more help , the box is a good idea but if you have 5 or more people to thanks it is not a good idea , to copy and paste

    If i want to add a new button under the avatar and the name i must modifiy the template

    messageSidebar and create a new group by exemple mypersonaltemplate it is correct ?

    <div class="messageAuthorContainer">
                    <a href="{link controller='User' object=$userProfile->getDecoratedObject()}{/link}" class="username userLink" data-user-id="{@$userProfile->userID}"{if $enableMicrodata} itemprop="url"{/if}>
                        <span{if $enableMicrodata} itemprop="name"{/if}>{if MESSAGE_SIDEBAR_ENABLE_USER_ONLINE_MARKING}{@$userProfile->getFormattedUsername()}{else}{$username}{/if}</span>
                    {if $userProfile->banned}<span class="icon icon16 fa-lock jsTooltip jsUserBanned" title="{lang user=$userProfile}wcf.user.banned{/lang}"></span>{/if}
                    {event name='messageAuthorContainer'}

    and insert a new <div> under this code

        <button class="mythanksbutton" onclick="insertName($username)">Thanks</button>

    and create a jscript

    if have many questions

    where i must write my new jscript , in wich template ?

    when i modify a template , how the new template is used and not the default template

    what is the name of redactor inside the forum , i found the code on redactor site

    Thanks for your help

  • Yes, this is a possible implementation path.

    Since I have not yet dealt with the editor myself, I can not help you with your javascript inserting the names in the editor area. The script element can be inserted in the mentioned messageSidebar template.

    <script data-relocate="true">
        $(function() { 
            elByClass('mythanksbutton')[0].addEventlistener(WCF_CLICK_EVENT, function(event) {
                // here your code inserting the information in the editor

    The name and the link of the user can be stored in data-attributes by the button element.

    <button class="mythanksbutton" data-link="{link controller='User' object=$userProfile->getDecoratedObject()|encodeJS}{/link}" data-username="{$userProfile->getDecoratedObject()->username|encodeJS}">Thanks</button>

    You can access the values by the following:

    var link = elData(event, 'link');
    var username = elData(event, 'username');

    With these information you can build the link and insert the link in the editor.

    The created template group has to be selected in the style. Otherwise the default group will be used.

  • try it

    but i have a error and don't understand it

    TypeError: e.getAttribute is not a function
  • My fault. Please use var username = elData(event.currentTarget, 'username'); instead of var username = elData(event, 'username');.

  • JavaScript
    var username = "marcbelgique";
    $('#text').redactor('insert.text', username);

    The method insert.html differs by treating the passed arguments as a HTML string, which comes in handy when you want to link to the actual user profile.

    when i use your code or insert.html , i have a problem , if the username is admin , i have adminadmin in redactor

    and if i try window.alert (username) , i have two time the window.alert

    try with elBysel

    and the same problem with two time the name and the window.alert

  • when i look in the html page

    my script is two time too , if i remove the script of my template , there are nothing (thus it is only one time ) , if i add the script on my template , it is too time in my html page...

    An idea ?

    • Official Post

    If somebody can explain this code , i'm very happy to understand

    Basically, your template is output more than once, and so is your JavaScript. Because it appears multiple times, it is also executed multiple times, causing more and more click handlers to be bound to the button. Each handler operates independently from others, so they start stacking up and causing the same code to be executed in parallel.

    The tiny template scripting wrapper above simply checks if a specific variable is set, and if not, sets it and outputs your JavaScript code. On the next code iteration, the variable will be set and the JavaScript is not presented to the browser again. Of course this only works because the variable isn't set already, so if you want to re-use it, pick a new variable (the more strange it sounds, the more likely it's going to be not used already).

    tl;dr: Prevents your JavaScript code from appearing more than once on your page.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!