Passing variables between templates

Author Message

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...

martin k

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

martin k

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 time
i 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

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

eZ debug

Timing: Jan 18 2025 11:19:54
Script start
Timing: Jan 18 2025 11:19:54
Module start 'layout'
Timing: Jan 18 2025 11:19:54
Module start 'content'
Timing: Jan 18 2025 11:19:55
Module end 'content'
Timing: Jan 18 2025 11:19:55
Script end

Main resources:

Total runtime0.9576 sec
Peak memory usage4,096.0000 KB
Database Queries75

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0061 588.0313152.6406
Module start 'layout' 0.00610.0035 740.671939.4609
Module start 'content' 0.00960.9463 780.1328689.0391
Module end 'content' 0.95600.0016 1,469.171916.1563
Script end 0.9576  1,485.3281 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.3271160.0002
Check MTime0.00130.1405160.0001
Mysql Total
Database connection0.00100.105910.0010
Mysqli_queries0.894393.3852750.0119
Looping result0.00090.0914730.0000
Template Total0.924496.520.4622
Template load0.00200.211520.0010
Template processing0.922496.324120.4612
Template load and register function0.00020.025310.0002
states
state_id_array0.00120.123410.0012
state_identifier_array0.00120.123420.0006
Override
Cache load0.00170.1783340.0001
Sytem overhead
Fetch class attribute can translate value0.00070.075650.0001
Fetch class attribute name0.00140.150090.0002
XML
Image XML parsing0.00140.149650.0003
class_abstraction
Instantiating content class attribute0.00000.001890.0000
General
dbfile0.00100.1003240.0000
String conversion0.00000.000940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 22
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs