DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Is there a way to use Tokens in the Page Header Tags under Site Settings? Or an alternate way to add the Username in the header?

 4 Replies
 3 Subscribed to this topic
 40 Subscribed to this forum
Sort:
Author
Messages
New Around Here
Posts: 2
New Around Here

I have some javascript that I want on each page for analytics, but I would like it to include the username of the current user on the page.   The analytics will accept the data in JSON form, and I saw the [User:Username] token in my research, however, it does not render in the Page Header Tags where I have my script.  I've also tried razor and asp code but they simply render and do not execute.  I'm new to DNN so any help would be greatly appreciated. 

The following is the code that I have tried:


 

       
       

 
 
Veteran Member
Posts: 1246
Veteran Member
MVP
MVP
You're an MVP!
Yes!

This is a good place to start: https://stackoverflow.com...e-properties-in-skin

Without further checking, I think that GetCurrentUserInfo().Username is what you need. In other words ...

[% =UserController.GetCurrentUserInfo().Username %]

Replace the square brackets with the usual angled brackets ...
New Around Here
Posts: 2
New Around Here
Thank you Joe, but in that section, it does not appear to execute server-side code, but rather renders it as text. I'm not familiar enough with how to edit skins or templates directly, which is why I am trying to accomplish this through the settings. Below is a screenshot of my settings:
Senior Member
Posts: 1322
Senior Member
3 Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
Lifesaver
Lifesaver
You're Life Saver!
New Poster
New Poster
Congrats on posting!
3 Engaged Reader
Engaged Reader
You are an engaged reader!
Posted By GPaul on 04 Nov 2020 03:02 PM

I have some javascript that I want on each page for analytics, but I would like it to include the username of the current user on the page.   The analytics will accept the data in JSON form, and I saw the [User:Username] token in my research, however, it does not render in the Page Header Tags where I have my script.  I've also tried razor and asp code but they simply render and do not execute.  I'm new to DNN so any help would be greatly appreciated. 

As you noticed there is no Code / token replace "support" in the Page Header tag field.
If you want to add this to all your pages, I would suggest adding code to yout Theme / Skin file.
We have a free skin with a lot of examples: https://demo.40fingers.ne...s-demo-skin/Security

If that's not what you want, you could use a templatable module like Open Content.
You don't need to use any of the fancy editing features, it also allows you to just inject a razor file on a page.
In short:

- Install Open Content
- Place the module on a page (this generatres the folder below)
- In the file system, open Portals/[portalfolder]/OpenContent/Templates
- Create a folder "Analytics" to hold your razor file
- Create a template.cshtml file and add this content:
<code>< script><br /> alert("@Dnn.User.Username");<br /> < /script></code>
- Refresh te page where you placed OC and select the newly created file.

 

 

New Around Here
Posts: 1
New Around Here
you will have to have the token in html then grab it with JavaScript.

[User:Username]



These Forums are for the discussion of the open source CMS DNN platform and ecosystem.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
  2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
  3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  5. No Flaming or Trolling.
  6. No Profanity, Racism, or Prejudice.
  7. Site Moderators have the final word on approving / removing a thread or post or comment.
  8. English language posting only, please.

Would you like to help us?

Awesome! Simply post in the forums using the link below and we'll get you started.

Get Involved