Return value from a snippet

Hi,
I am working on a members’ site, where users have a front end login. Currently I have a chunk of code at the top of every page template that checks if a user is logged in, what role they have, and then a bunch of other bits depending on the role. I use this to set variables, which are then used further down the page to decide what content is shown.

This chunk of code looks like a great candidate for a snippet, but I am not sure if I can get a snippet to return information like that. I know I can pass variables into snippets, but can I get variables out? Is there another way of achieving this using another method?

Thanks for any insight anyone has!

This code looks like the perfect candidate for a controller, I’d say.

I hadn’t even thought of that! Thanks :slightly_smiling_face: