Forums / Setup & design / Passing variables between templates
martin k
Friday 14 October 2005 6:26:46 am
Hello,
I'm wondering how I can pass variables between templates. More speficially, I need to show the logged in username on top of the page regardless of which page the user is looking at.
Right now I use the following code in pagelayout.tpl, but it works only in this template:
{def $user=fetch( 'user', 'current_user' )} User: {$user.contentobject.name} <br />
I would like to show this variable in a template named top.tpl (part of static content). But the code above doesn't return any value.
I think the solution is to pass the variable along, but how? This is EZ publish 3.6.1 btw. Thanks for any suggestions.
Nathan Kelly
Friday 14 October 2005 6:40:14 am
Hi, I'm not sure if this will help I havn't had to deal with this problem yet but it may be worth a look.
http://ez.no/community/forum/developer/passing_variables_parameters_between_templates
Hope it helps.
Cheers!
Pardon me while I burst into flames...
Friday 14 October 2005 9:52:39 am
I've looked at forum reply you linked to earlier to day. Unfortunately this doesn't solve my problem. I don't want to pass any variables in the URL. I've tried setting a <input type="hidden value="myvar"> field, but this variable isn't passed along if you don't have a submit button in the form.
I guess if I don't find any solution, I'll just merge my top.tpl with pagelayout.tpl and don't bother with passing variables.
Konrad Mazurkiewicz
Friday 14 October 2005 12:54:16 pm
Hi, if you want to show username on every page, you may place this piece with fetch on the top of pagelayout.pl. Next, use cache-block with apriopriate key around this to properly cache. This should be enough.Konrad
Tuesday 18 October 2005 2:51:51 am
Thank you for your suggestions :) We went the easy way and just merged our top.tpl template into pagelayout.tpl. But I never knew a cache-block could be used to pass variables. I'll have this in mind for a later occasion.
Mazen Alsibai
Wednesday 19 October 2005 5:11:03 am
Hi: the solution is a little difficult, you have to fetch the current user in php file(index.php)and then put it in session variable that is available all the timei wish that help
Marko Žmak
Wednesday 19 October 2005 3:11:59 pm
Just one question. How can you put some value into session variable in eZ?
-- Nothing is impossible. Not if you can imagine it! Hubert Farnsworth