User-specific layout options

juddster

Joined: 2005-01-25
Posts: 23
Posted: Wed, 2005-04-13 18:21

I'm hacking together a quick layout, based on the matrix layout. What I'd like to do is make the appearance of the sidebar dependent on the user i.e. if user=admin, then show the sidebar so can add/edit etc, but if user is not admin, then no sidebar.

I'm still getting to grips with the impressive coding of Gallery2, and can't figure out what the if condition would be - if anyone knows it, or something similar that will point me in the right direction, then please let me know!

Thanks in advance, Judd

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Wed, 2005-04-13 18:29

we don't yet have a simple test.. eventually we'll probably add something like $user.isAdmin
for now you can try
{if $layout.user.id==5}...{/if}
put this around the include for sidebar.tpl. it will work only for the actual "admin" user; when we add $user.isAdmin this will work for any user you add to the Administrators group.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-04-13 18:32

you'll have to create a layout variable in the php part of the layout
$ret = assertUserIsSiteAdministrator();
if ($ret->isSuccess())
isadmin = true;
} else {
isadmin = false;
}

and then you have to add this variable to the template variables and in the .tpl files, you can use it with the smarty if tags.

 
juddster

Joined: 2005-01-25
Posts: 23
Posted: Wed, 2005-04-13 19:57

Thanks to both of you! I've initially gone for the first smarty-based solution, though may end up opting for the second option if I use the same conditional in other parts of the layouts.

I noticed that the layouts are commented as saying that the whole layout engine may change - does this mean a move away from Smarty? I.e. will the layout I'm creating now soon be obsolete?

BTW, I'm sure it's been said before, but what an awesome codebase! I'm a big fan of OO design and XP, great to see those unit tests!

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Wed, 2005-04-13 20:12

no, i don't think we'll drop smarty.. where do you see this comment? the only text i'm aware of is in README.html.
the only layout change i'm aware of on the horizon is allowing module views (like add comments, slideshow, etc) to have their content placed in the layout.. so the layout can add a sidebar, navigation links, etc and module views don't have to worry about it.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2005-04-19 18:38

I have made a standard template variable so user info is available to every view. You can reference these in any tpl: $user.userName, $user.fullName, $user.isGuest, $user.isRegisteredUser, $user.isAdmin
Update from cvs in a few hours or get tomorrow's nightly snapshot to try this out. If you have any references to $layout.user in your local tpl files you'll need to change these to just $user.