cancel
Showing results for 
Search instead for 
Did you mean: 
Alexandre_Sch
Community Contributor

Render student name from a html page

Jump to solution

Hi Canvas Team, 

I know canvas is capable of rendering the name and other variables of the student using some pre-created variables. Where i can found those variables? 

The main goal here is creating a page sending a HI, <studentName>!! and so on. 

Regards,
Alexandre S.

2 Solutions

Accepted Solutions
Alexandre_Sch
Community Contributor

Hi Kelley, 

Thanks for your answer. Nice to know all the possibilities when working with html on canvas. I used a javascript that find for a expression that i created and replace it for the student full name using ENV.current_user.display_name and managed to do what i wanted. 

Regards,
Alexandre S.

View solution in original post

Hi!!

 

Sure, you just need to use: "ENV.current_user.display_name" (you can try use this on console to check the result, it will render the student name).

 

You can implement by: 

Create a Canvas page inside a course and in the html editor do something like: <span id="userName"></span> and into your JS file (that need to be loaded on every canvas page, or just everywhere if u want) you need something like: document.getElementById("userName").innerHTML = ENV.current_user.display_name

Doing that, every page that has the id="userName" or anyone you choose, it will render the student's name. 

 

Hope it helps!

View solution in original post

7 Replies
kmeeusen
Community Coach
Community Coach

Hi  @Alexandre_Sch 

Canvas does not make use of tokens, and most any executable code included in page content via the UI, is promptly stripped out. You can find the allowed HTML elements for Canvas at Canvas Whitelist

Kelley

Alexandre_Sch
Community Contributor

Hi Kelley, 

Thanks for your answer. Nice to know all the possibilities when working with html on canvas. I used a javascript that find for a expression that i created and replace it for the student full name using ENV.current_user.display_name and managed to do what i wanted. 

Regards,
Alexandre S.

View solution in original post

Robbie_Grant
Community Coach
Community Coach

 @Alexandre_Sch ,

Were you able to find an answer to your question? I am going to go ahead and mark this question as answered because there hasn't been any more activity in a while so I assume that you have the information that you need. If you still have a question about this or if you have information that you would like to share with the community, by all means, please do come back and leave a comment.  Also, if this question has been answered by one of the previous replies, please feel free to mark that answer as correct.

 

Robbie

Hi @Alexandre_Sch 

I'm hoping to achieve the same result...grab the student name and add it to a Canvas page.

Do you mind sharing your solution and code? I would greatly appreciate it. 🙂

Best,

Veronica

Hi!!

 

Sure, you just need to use: "ENV.current_user.display_name" (you can try use this on console to check the result, it will render the student name).

 

You can implement by: 

Create a Canvas page inside a course and in the html editor do something like: <span id="userName"></span> and into your JS file (that need to be loaded on every canvas page, or just everywhere if u want) you need something like: document.getElementById("userName").innerHTML = ENV.current_user.display_name

Doing that, every page that has the id="userName" or anyone you choose, it will render the student's name. 

 

Hope it helps!

View solution in original post

Thank you so much @Alexandre_Sch It worked perfectly!

I did have one more question - I was curious - is there a way to pull just the first name and not the last name onto the page?

Hey!

Glad it worked o/ 

 

I don't remember if exist a env for just the first name, but since you have the full name (ENV.current_user.display_name), you can use the js:split  (https://www.w3schools.com/jsref/jsref_split.asp) to get only the firstname of the user.