Forums | Mahara Community

Developers /
smarty and tpl files

anonymous profile picture
Deleted user
Posts: 4

16 May 2011, 1:56 PM

I'm making some minor customizations to Mahara and we'd like to have the user's username appear in the footer. Is there a way to have this variable visible in the footer.tpl without having to go into each codebehind for the tpl files?

For example, this works:

I put this in view/view.php:

and I put this in footer.tpl:

If I then hit view/view.php, I see the username in the footer. I'm hoping not to have to do the above assign() for each php page that uses smarty though.

I do see in footer.tpl that {$WWWROOT} is visible to this template, and I don't see that it's assigned via $smarty->assign in pages such as \view\view.php, so I'm thinking there must be a way to globally set a variable that will be visible to all the .tpl files.


Iñaki Arenaza's profile picture
Posts: 253

23 May 2011, 3:09 PM

{$WWWROOT} is assigned in the Dwoo_Mahara class constructor. See lib/dwoo/mahara/Dwoo_Mahara.php 


anonymous profile picture
Deleted user
Posts: 4

31 May 2011, 9:39 AM

I see it now. That is helpful. Thanks very much.

anonymous profile picture
Deleted user
Posts: 214

14 June 2011, 8:15 AM


You don't mention what version of mahara you're using, but if you have a look at lib/web.php -> smarty() and search for assign_by_ref('USER' you'll see that the user variable is already always assigned to templates so you should be able to use this relatively easily.

The theme change you want is probably more akin to:

{if $USER->is_logged_id()}{$USER|display_name}{/if}

Of course, I'd highly recommend that if you're doing this you should do it in the following way:

  • Create a new theme - e.g. theme/customraw
  • Modify any other themes, except for the raw theme to use this theme as their parent
  • Add a new footer template to your customraw theme which makes the change you're after

I'd really advise against making changes to the raw theme as you'll find things get difficult to upgrade in the future.

Hope that this helps,


anonymous profile picture
Deleted user
Posts: 4

11 July 2011, 2:56 PM

Thanks for this additional useful information. Very helpful.

5 results