The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Username in Templates...

View previous topic View next topic Go down

Solved Username in Templates...

Post by Rocker92 on November 7th 2011, 5:58 pm

Hey guys,

I have recently used a script from the French Support Forums: http://forum.forumactif.com/t260631-astuce-utiliser-les-variables-user-et-forum-autre

Now it's working, but only for staff. If the user is not in a staff user group. The name does not show up.

Here is the code that I'm using, it's in the index_body, just under the {JAVASCRIPT} variable.
Code:
<div id="user_info">
  <!-- BEGIN switch_user_logged_in -->
  <div id="user_avatar" class="fl"><!-- avatar here --></div>
 
    Welcome Back, <span class="USERNAME"></span> <br /><br />
 
  <div id="add_links">
       <ul>
       <li><a href="{U_SEARCH_NEW}">{L_SEARCH_NEW}</a></li>
       <li><a href="{U_SEARCH_SELF}">{L_SEARCH_SELF}</a></li>
      <li><a href="{U_SEARCH_UNANSWERED}">{L_SEARCH_UNANSWERED}</a></li>
      <li><a href="{U_MARK_READ}">{L_MARK_FORUMS_READ}</a></li>
   </ul>
  </div>
  <!-- END switch_user_logged_in -->
  <!-- BEGIN switch_user_logged_out -->
    <p>Hello Guest,<br /> It appears that you are not logged in or that you have not registerd. You can Log-in or Register bellow!</p><br />
   
    <a href="http://code-phase.forumotion.co.uk/login"> <img src="http://i43.servimg.com/u/f43/16/93/80/74/login10.png" alt="Log-In" /></a>
    <a href="http://code-phase.forumotion.co.uk/register"> <img src="http://i43.servimg.com/u/f43/16/93/80/74/regist10.png" alt="Log-In" /></a>
  <!-- END switch_user_logged_out -->
</div> <!-- end user_info -->

And here is the javascript:
Code:
function treatvar(nom) {
    var trouve = xhr.responseText.replace(RegExp("^.+<li style=\"margin-bottom:5px;direction:ltr;text-align:left;\"><strong>{" + nom + "}<\/strong>:(.*?)<span style='direction:ltr'>\(.*?\)<\/span><br \/><\/li>.+$"), '$1');
    if (xhr.responseText == trouve) return;
    var children = document.getElementsByTagName('*') || document.all;
    var v = new Array();
    var i = -1;
    while (++i < children.length) {
        var child = children[i];
        var classNames = child.className.split(' ');
        for (var j = 0; j < classNames.length; j++) {
            if (classNames[j] == nom) {
                v.push(child);
                break;
            }
        }
    }
    i = -1;
    while (++i != v.length) if (v[i].tagName == 'INPUT' || v[i].tagName == 'TEXTAREA') v[i].value += trouve;
    else v[i].innerHTML += trouve;
};
if (window.ActiveXObject) {
    var xhr = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
    var xhr = new XMLHttpRequest();
}
if (xhr != null) {
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4) {
            treatvar('FORUMURL');
            treatvar('FORUMURLINK');
            treatvar('FORUMNAME');
            treatvar('FORUMNAMELINK');
            treatvar('FORUMDESC');
            treatvar('FORUMBIRTHDAY');
            treatvar('FORUMAGE');
            treatvar('FORUMCOUNTFORUM');
            treatvar('FORUMCOUNTOPIC');
            treatvar('FORUMCOUNTPOST');
            treatvar('FORUMCOUNTUSER');
            treatvar('FORUMONLINEUSER');
            treatvar('FORUMONLINEDATE');
            treatvar('FORUMLASTUSER');
            treatvar('FORUMLASTUSERLINK');
            treatvar('USERNAME');
            treatvar('USERLINK');
            treatvar('USERBIRTHDAY');
            treatvar('USERAGE');
            treatvar('USERREGDATE');
            treatvar('USERLASTVISIT');
            treatvar('USERCOUNTPOST');
        }
    };
    xhr.open("GET", "/popup_help.forum?l=miscvars", true);
    xhr.send(null);
}

Rocker92
Forumember

Male Posts : 737
Reputation : 117
Language : English & French
Location : Atlanta, GA

http://www.code-artist.com/

Back to top Go down

Solved Re: Username in Templates...

Post by Guest on November 7th 2011, 6:07 pm

I don't know exactly, but... Try to create a invisible group, I mean Group status : Hidden group, Group auto-subscribe : Yes and Minimum Posts : 0. Something like Members +50

It's first thing appears in my mind. Hello

Guest
Guest


Back to top Go down

Solved Re: Username in Templates...

Post by LGforum on November 7th 2011, 6:13 pm

Wait all that just to include the username in a template?

But its surely such an easy task, when I get back at my computer I'm gonna look into this. I can already think of a much easier way of doing this.

LGforum
Hyperactive

Male Posts : 2260
Reputation : 258
Language : English
Location : UK

http://www.avacweb.com/

Back to top Go down

Solved Re: Username in Templates...

Post by Rocker92 on November 7th 2011, 6:24 pm

Gassy wrote:I don't know exactly, but... Try to create a invisible group, I mean Group status : Hidden group, Group auto-subscribe : Yes and Minimum Posts : 0. Something like Members +50

It's first thing appears in my mind. Hello

Already tried that Wink

@LGforum wrote:Wait all that just to include the username in a template?

But its surely such an easy task, when I get back at my computer I'm gonna look into this. I can already think of a much easier way of doing this.

OK, thanks Smile

Rocker92
Forumember

Male Posts : 737
Reputation : 117
Language : English & French
Location : Atlanta, GA

http://www.code-artist.com/

Back to top Go down

Solved Re: Username in Templates...

Post by LGforum on November 7th 2011, 7:12 pm

Lol yes as i suspected it was much easier than i thought.
There was no need for Ajax requests at all.

So i only did it with the username variable since it seemed thats all you wanted but the same method can be used for all the other variables.

First put this:
Code:

<span id="username" style="display:none">{*USERNAME}</span>
Into somewhere where you can put HTML, i put it in the forum description box. (obviously remove the * )

Then put this into a javascript file:
Code:

$(document).ready(function() {
var x=$('#username').html();
$('.templateuname').html(x);
});

Name it what you want.

and then in the templates wherever you want to put the username put:
Code:
<span class="templateuname"></span>
You can put this in as many places as you want in the template.

Worked for me, so im guessing it should work for you. Wink

LGforum
Hyperactive

Male Posts : 2260
Reputation : 258
Language : English
Location : UK

http://www.avacweb.com/

Back to top Go down

Solved Re: Username in Templates...

Post by Rocker92 on November 7th 2011, 8:09 pm

Thanks mate Smile

Solved

Rocker92
Forumember

Male Posts : 737
Reputation : 117
Language : English & French
Location : Atlanta, GA

http://www.code-artist.com/

Back to top Go down

Solved Re: Username in Templates...

Post by Nera. on November 8th 2011, 7:04 pm

Lock

Nera.
Energetic

Female Posts : 7077
Reputation : 2013
Language : English
Location : -

http://webartzforum.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum