Forums / General / Can't access my vars!

Can't access my vars!

Author Message

Thomas Brandl

Monday 15 September 2003 6:00:27 am

Hi everybody,

I have a default statement in my pagelayout defining a couple of variables. I can access them inside pagelayout.tpl without any problem.

{default color_1=$background.0.data_map.color_1.data_text}
($background was fetched before)

I cannot access them from within any other template with {$#color_1}, error message is: "Unknown template variable 'color_1' in namespace '' " ({$color_1} isn't working neither, oc)

I thought, I had this working once....

So, how can I define and access global variables?

Thanks!!
t

Paul Borgermans

Monday 15 September 2003 6:23:29 am

Good question, would like to know too.

http://ez.no/developer/ez_publish_3/documentation/development/libraries/ez_template/functions/include

You can always pass them when including them.

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Thomas Brandl

Monday 15 September 2003 7:05:28 am

Thanks Paul, but still no luck!

With this approach, the vars aren't even visible to my pagelayout anymore!
I did this:
- create a template with a {let fetch=..} and a default block.
- Include it in pagelayout
- Try to access the variables ..

The thing is, I am closing the let-and default block inside the include. Aren't they freed when you close the block? So after the include, they do not exist anymore...

I just found out, that I can see the variables inside templates, that are included by pagelayout, but I can't see them inside {$module_result.content}. But that's where I need them!

Sigh...
t

Paul Forsyth

Monday 15 September 2003 7:12:17 am

This is puzzling. Could you perhaps give a distilled example of your code with the template logic you use? Its hard to see exactly where your problem starts...

thanks

paul

Thomas Brandl

Monday 15 September 2003 7:47:50 am

Sure, try to keep it as simple as possible:

Approach No 1:
pagelayout.tpl:
{let bg=fetch(content,list,...)}
{default color_1=bg.0.data_map.color_1.data_text}
<html>
<body>
this works: {$color_1} is my color.
{include uri='mynav.tpl'} {* below *}
{$module.result}
</body>
</html>
{/default}
{/let}

mynav.tpl:
this works too {$color_1} or {$#color_1}

---------------------------
Approach No 2:
pagelayout.tpl
<html>
<body>
{include uri='someincludes.tpl'}
{$color_1} and {$#color_1} are not there!
{$module.result}
</body>
</html>

someincludes.tpl:
{let bg=fetch(content,list,...)}
{default color_1=bg.0.data_map.color_1.data_text}
{/default}
{/let}

But whatever happens inside {$module.result}, the color_1 var cannot be accessed. I need them later in override-templates.

I'm not sure whether this behaviour is by design, but there must be a way to define global (really global!) variables, no?

Thanks guys!
t

Paul Forsyth

Monday 15 September 2003 8:37:33 am

Ah, this is a scope issue. Normally any variables you set within an include will be released when you come back from that include. What you are doing may not be possible. Also your included template has a {let}{/let}. When the template code reads the final {/let} the variables defined by your initial {let} will be released.

This thread discusses a little about your problem:

http://ez.no/developer/ez_publish_3/forum/developer/using_letset_within_namespaces

If i were you i'd get rid of the default lines and include the variable assignment in the top level {let}. Also, try not specifying the final {/let}.

For example:

pagelayout.tpl
{let name=MyScope
-----color_1=0}
{include.....}
{/let}

included_file:

{let bg=fetch(content,list,...)}
{set color_1=$MyScope:bg.0.data_map.color_1.data_text}
{/let}

This should let you use color_1 outside of your lets...

You may have more luck trying this approach but i honestly don't know if it will work. Im not sure if ez templates allow you to pass variables back from one template to another...

paul

Thomas Brandl

Monday 15 September 2003 9:18:21 am

I also tried the let/set combination, without success.
There's actually no special demand for me to use includes.tpl, all I need is all other templates to be able to access the vars defined in pagelayout.tpl.

{set-block} made me hope for a second, bc you can specify a scope for it. the root scope however doesn't include {$module_result.content} neither.

Too bad it doesn't seem to be possible by now!
sigh again...

Have a nice evening!
t

Paul Forsyth

Tuesday 16 September 2003 12:22:15 am

Yip, this aspect of template programming is weak. Hopefully it will improve soon, along the lines spoke about in the link i gave.

Paul

eZ debug

Timing: Jan 30 2025 21:37:04
Script start
Timing: Jan 30 2025 21:37:04
Module start 'content'
Timing: Jan 30 2025 21:37:04
Module end 'content'
Timing: Jan 30 2025 21:37:04
Script end

Main resources:

Total runtime0.1774 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.0073 587.8203370.3125
Module start 'content' 0.00740.0125 958.13281,009.4531
Module end 'content' 0.01990.1574 1,967.58593,898.1641
Script end 0.1773  5,865.7500 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00442.4772200.0002
Check MTime0.00130.7356200.0001
Mysql Total
Database connection0.00080.428910.0008
Mysqli_queries0.089650.53421410.0006
Looping result0.00130.75201390.0000
Template Total0.157088.510.1570
Template load0.00080.457610.0008
Template processing0.156288.055110.1562
Override
Cache load0.00050.305010.0005
Sytem overhead
Fetch class attribute can translate value0.00221.249310.0022
XML
Image XML parsing0.00030.152310.0003
General
dbfile0.00301.7088200.0002
String conversion0.00000.003930.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.0002 secs