Display Student Name in Assignment texts

Display Student Name in Assignment texts

by Gustav Joubert -
Number of replies: 3

Hi,

Can anyone tell me how to grab the logged in student name and display it inside the assignment source, example:

"Hi <P><?=$loggedinas ?></P>, this assignment is to test your way of thought"

Then it must display

"Hi Martin, this assignment is to test your way of thought"

I have looked at the "footer.html" file and tried it in the source, but it displays the code after I close the source view option.

Any ideas ?

Average of ratings: -
In reply to Gustav Joubert

Re: Display Student Name in Assignment texts

by Loren Winfrey -

Here is the code to display the name, but it may not work in the assignment...

<? echo "$USER->firstname $USER->lastname"; ?>
I tried to add it within an assignment and didn't get it to work..
 
sorry.
In reply to Loren Winfrey

Re: Display Student Name in Assignment texts

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Yes, PHP is not currently parsed within any course texts (which is good for security).

A limited form of variable substitution might be a good feature for the future though.
In reply to Gustav Joubert

Re: Display Student Name in Assignment texts

by Paula Edmiston -
I don't know if you'd find this a desirable compromise ... I am placing the user's name at the top of the window, replacing the logout links. The person's name is a logout link and when you hover the link the link title shows up saying "logout".

Edited two files: one for the moodle home page and one for subsequent pages.

1. display the user name on the home page, centered just under the logo

edit theme/mm/header.html at about line 17, just under the line that calls the logo (in the standard logo theme, but note that theme/mm is my personal theme) I inserted this:

<!-- paula added display of user name next line -->
<br><center><font size="1">
<a href="/cweb/login/logout.php" title="Logout"><? echo "$USER->firstname $USER->lastname"; ?><$
</font></center><!-- stop paula -->


2. Now, replace the existing text "logout" link with the user name as logout link. again, the title attribute provides a reminder label when you hover the link. Edit lib/weblib.php at about line 597

// paula this replaces the logout link text with the user name - replace the following line
// $menu = "<FONT SIZE=2><A TARGET=_parent HREF="$CFG->wwwroot/login/logout.php" >".get_string("logout")."</A></FONT>";
// with this new line

$menu = "<FONT SIZE=2><A title="Logout" TARGET=_parent HREF="$CFG->wwwroot/login/logout.php">$USER->firstname $USER->lastname</A></FONT>";

// stop paula

Please notice that on that line of code above 'stop paula' it should be one unbroken line but it wraps in this window.