eZ Community » Forums » General » Can't access my vars!
expandshrink

Can't access my vars!

Can't access my vars!

Monday 15 September 2003 3:00:27 pm - 7 replies

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

Monday 15 September 2003 3:23:29 pm

Good question, would like to know too.

http://ez.no/developer/ez_publish...raries/ez_template/functions/include

You can always pass them when including them.

-paul

Monday 15 September 2003 4:05:28 pm

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

Monday 15 September 2003 4:12:17 pm

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

Monday 15 September 2003 4:47:50 pm

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

Modified on Monday 15 September 2003 4:50:27 pm by Thomas Brandl

Monday 15 September 2003 5:37:33 pm

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

Modified on Monday 15 September 2003 5:42:47 pm by Paul Forsyth

Monday 15 September 2003 6:18:21 pm

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

Tuesday 16 September 2003 9: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

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from