Forums | Mahara Community

Developers /
Display dynamic message on homepage


Andrew Field's profile picture
Posts: 10

01 May 2015, 1:55 AM

Hi,

Is it possible to display a dynamic message according to the logged in user profile?

I'm currently using Mahara 1.7 and I believe it is possible to use something like:

{if $USER->is_institutional_staff()}
<!---Block of html for teachers--->
{else}
<!---Block of html for everyone else--->
{/if}

However, I've tried adding this to the 'show homepage information' text from the admin area and it is just displayed as text.   Is there something I'm missing?

Thanks for any assistance you can provide.

Andrew Field's profile picture
Posts: 10

01 May 2015, 7:10 AM

I'm guessing maybe this needs to be added directly to the template file rather than within the editing options in Admin?

Aaron Wells's profile picture
Posts: 896

01 May 2015, 12:21 PM

You are correct. Smile

Cheers,

Aaron

Andrew Field's profile picture
Posts: 10

01 May 2015, 10:04 PM

Thanks for the reply Aaron - much appreciated.

Kristina Hoeppner's profile picture
Posts: 3366

03 May 2015, 8:50 PM

Hello Andrew,

Another possibility (but only in later versions of Mahara) is the following which wouldn't require coding: If you have not hooked up your Mahara to a Moodle site, you could put all your teachers into one institution and all your students into another. And then you can set different messages for them on the homepage. See http://manual.mahara.org/en/15.04/administration/institutions.html#institution-static-pages for more information.

The added benefit is that you could also give your teachers a different theme than what the students get and give them different permissions in terms of public pages, seeing online users etc.

Cheers

Kristina

 

Andrew Field's profile picture
Posts: 10

07 May 2015, 3:19 AM

Thanks - this is all useful information to experiment with.  When I've got it working I will report back with what I've used.

Andrew Field's profile picture
Posts: 10

23 May 2015, 2:47 AM

Just to follow up - we've got this working now exactly as proposed.  By updating the homeinfo.tpl file we've got a dynamic display that shows content depending on the user profile.

 

Kristina Hoeppner's profile picture
Posts: 3366

24 May 2015, 3:20 PM

Hi Andrew,

Great that you got it to work. Do you have a write-up of your idea to share with others in case someone is interested in your solution to achieve something similar?

Cheers

Kristina

 

Andrew Field's profile picture
Posts: 10

22 June 2015, 11:05 PM

Hi - there isn't actually too much more the solution than the original request.  However, I would be happy to write up if that will help others.

In fact, I have since discovered a further challenge:

{if $USER->is_institutional_staff()}
<!---Block of html for teachers--->
{else}
<!---Block of html for everyone else--->
{/if}

works really well as it displays teacher content for teachers and then changes it for others.  However, as we've some some users who aren't institutional staff I'm actually looking to change the code so it will display specific content to students instead.

It is turning the code on its head really.

However, is this a valid command or is there anything similar that anyone is familiar with?

if $USER->is_student()

Could be used for:

{if $USER->is_student()}
<!---Block of html for students--->
{else}
<!---Block of html for everyone else--->
{/if}

Aaron Wells's profile picture
Posts: 896

24 June 2015, 11:14 AM

Hi Andrew,

Sorry, we don't have an "is_student()" function. We've actually never had a use for it in Mahara core, because admins & staff can do everything students can do.

So, you'll just need to check that the user isn't staff or admin:

{if !($USER->get('admin') || $USER->get('staff') || $USER->is_institutional_admin() || $USER->is_institutional_staff())}
<!-- block of HTML for students -->
{else}
<!-- block for everyone else -->
{/if}

Cheers,

Aaron

13 results