Forums / Setup & design / Passing variables between templates

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

eZ debug

Timing: Jan 30 2025 21:16:48
Script start
Timing: Jan 30 2025 21:16:48
Module start 'content'
Timing: Jan 30 2025 21:16:48
Module end 'content'
Timing: Jan 30 2025 21:16:48
Script end

Main resources:

Total runtime0.1917 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0072 588.0313370.2891
Module start 'content' 0.00720.0136 958.32031,005.6563
Module end 'content' 0.02080.1708 1,963.97663,894.2422
Script end 0.1916  5,858.2188 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00472.4411200.0002
Check MTime0.00130.6994200.0001
Mysql Total
Database connection0.00060.338510.0006
Mysqli_queries0.096250.17391410.0007
Looping result0.00130.68201390.0000
Template Total0.170388.910.1703
Template load0.00090.454910.0009
Template processing0.169588.402010.1695
Override
Cache load0.00050.273410.0005
Sytem overhead
Fetch class attribute can translate value0.00201.033410.0020
XML
Image XML parsing0.00030.140910.0003
General
dbfile0.00663.4680200.0003
String conversion0.00000.003630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs