Accessing variables that were set in pagelayout.tpl

Author Message

Deane Barker

Thursday 18 August 2005 5:18:06 pm

I would like to set a variable in pagelayout.tpl (at the very top of the template "tree") then access it anywhere in the following included templates.

I have tried everything with set, let, def, namespaces, etc. I've been working on it for an hour, and I've read every shred of documentation. Global namespace or not, I simply cannot access a variable set in pagelayout.tpl from a deeply nested include.

Can this be done?

If so, does someone have some working code that shows it can be done? I've tried about every code sample I've found.

(Specifically, I have some code at the top of pagelayout.tpl that checks if the current user is in the 'Administrators' group:

{let $currentUser = fetch( 'user', 'current_user' )}
{if $currentUser.role_id_list|contains( '2' )}
	{def $is_admin=1}
{/if}
{/let}

There are several places in the templates below that where I want to use to decide whether to show or not show certain things.

What I'm struggling with is to show or not show the class-specific pop-up menu in full.tpl. I don't want people not in the Admnistrators group to be able to access this menu.)

Is there a better way to do this?

Valenti salas

Friday 19 August 2005 8:32:09 am

To read variables in all templates I use session vars. Try it, maybe can help you. You can modify or read the value of session vars everywhere, in templates and in kernel files.

Deane Barker

Friday 19 August 2005 8:41:10 am

That sounds like a decent plan. I have seen how to get at session values using ezhttp, but how do you set them in the first place from within template code?

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.