This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » Developer » Define a variable in pagelayout that...

Define a variable in pagelayout that could be used elsewhere

Define a variable in pagelayout that could be used elsewhere

Thursday 10 November 2011 2:31:13 pm - 8 replies

I there,

I would like to know if it is possible de create a variable in pagelayout and to use it in an override of view/full.tpl .

I already tryed :

{set-block scope=global variable=nom_partenaire}{$}{/set-block}

My variable is well accessible from pagelayout but node from my view/full.tpl override.


Any trick ?

Thursday 10 November 2011 2:56:00 pm


you could try persistent variables, i think. look at this

hope this help

juan pablo

Thursday 10 November 2011 2:57:45 pm

Your node is rendered before your pagelayout. That means that your variable is defined after anything rendered through {$module_result.content}, so this would not be possible.

Perhaps the data you're looking for is available through {$node.object}?

Thursday 10 November 2011 3:13:51 pm

Perhaps the data you're looking for is available through {$node.object}?

No, it's not, it is a node fetched through a relationlist in the user class (for the current user).

I wanted to send my datas to avoid fetching this information twice (I need it in pagelayout AND in my view/full).


you could try persistent variables, i think. look at this

hope this help

juan pablo

If I well understand you create the variable through the view/full to put it accessible to pagelayout. So you'll have to create this variable in each view/full ('cause I need this information on every pages). As I will not have a lot of pages for this website I'll give a try. Thanks.

Thursday 10 November 2011 3:21:59 pm

You already have the $current_user variable in the pagelayout's environment (pagelayout itself and templates included with {include uri='..'} from it), so there would only be one fetch in your full.tpl.

Thursday 10 November 2011 3:50:43 pm

I think you should get them back in full each view you need, then you can have themon pagelayout using persistent_variable

Thursday 10 November 2011 4:38:25 pm

Maybe javascript/ajax, maybe combined session variable would work for you?

Tuesday 10 July 2012 6:38:28 pm

I'm having a problem that would affect his issue.

Using the $current_user var is causing problems for me because all users get the rights and data of the last user who logs in, not the user they logged in as. User A logs in, then User B and C... all three users are logged in as User C.

I am having this issue when two people log into the same site as two different users from two different machines on the same network. I haven't tested if it happens when we're on two different networks.
I don't experience this issue when the view cache is turned off. But obviously that is not the solution.

To test for yourself and see if you get the same results:

I print out the $current_user var on the first line of website_toolbar.tpl and also on the first line of page_header.tpl using |attribute('show', 1).
If I log in as a regular member in Chrome I see the user object printing out the same content in both places.

However, if I log in as an administrator in a different browser, let's say IE8, on my machine or if I log in on a completely different computer (on the same network)... when I go back to my regular member browser and refresh the page, the $current_user var in website_toolbar.tpl shows the admin's info and the toolbar has content that only the admin should be able to see.

The $current_user var in page_header.tpl is still showing the correct regular member user info, despite the website toolbar having the wrong user's info.

I tried adding an if statement to check if the current user object was defined.
If current user isn't defined I fetch the current user info
if current user is defined, I replace it's contents by fetching the user object data anyway.

{if not(is_set($current_user))} {def $current_user=fetch(user, current_user)} {else} {set $current_user=''}{set $current_user=fetch(user, current_user)} {/if}
Still I get the Admin's info in website_toolbar.tpl even though he is not the currently logged in user in my other browser or on my other machine.

The user info that is returned from website_toolbar.tpl is the info of the last person who logged in.

One thing that fixed this problem was using the setting "pr_user" as the value of "ViewCacheTweaks[global]" under
"[ContentSettings]" in
"settings\siteaccess\public\site.ini.append.php" and

ViewCaching is enabled in the root site.ini file

I don't want to create a new cache for every user if it can be avoided
I tried "ignore_userroles" as the value of "ViewCacheTweaks[global]" thinking that this is the only issue so this should reduce the space utilization impact of the per user caching method.

ignore_userroles does nothing to solve this problem. The problem persists.
Why is this happening?
Any solution suggestions?

Tuesday 10 July 2012 9:16:50 pm

@Edgar if you don't want to generate a new version of the view cache per-user, and show username in the middle of the page (node view templates) I'd recommend to:

1. keep the standard viewcache configuration: one version of every page is generated in the viewcache for every user's group (to be more precise: for every set of users having the same roles and policies assigned)

2. get the current user's name in the pagelayout template (and templates included from it) and pass it down to the view template using some css or js magick

Storing user name in session as Huy suggested might make sense, but you'd still have to recover it in the pagelayout and use css/js tricks to show that info inside view-cached pages...

Using viewcachetweaks afaik is generaslly not used to make viewcache different per_user, but to do the opposite: make it be the same for all users regardless of their perms

Modified on Tuesday 10 July 2012 9:27:31 pm by Gaetano Giunta


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from