Forums / General / Any way to access persistent variables, ezgetvars(), or session variable via a /templates/content/datatype/view/ezxmltag/ template

Any way to access persistent variables, ezgetvars(), or session variable via a /templates/content/datatype/view/ezxmltag/ template

Author Message

Duffy Walsh

Friday 05 March 2010 6:36:05 pm

I have a very strange situation, and I need to have a conditional within a template that is included via a custom tag in the node's content.

I have attempted defining and setting a global scoped variable, but I am unable to retrieve it when the included template reloads. I have attempted passing query string variables, but I think because of how the template is included ezgetvars() are not available to it.

I have attempted defining and setting a global variable in pagelayout, but am not able to retrieve it in the included template with either $<variable_name> or $#<variable_name> with no luck. In looking through the forum I see this is because this template renders first.

So to be short, is there any way to access something like a Session variable from this /templates/content/datatype/view/ezxmltags/ template?

Duffy Walsh

Nicolas Pastorino

Monday 08 March 2010 5:48:29 am

Hi Duffy,

Indeed the inability to retrieve a variable set in the pagelayout from an included template is due to the execution order: first the view template, then the pagelayout.

To answer your last question : you can use the following operators to access any get, post or session variable from a template :

  • ezhttp: http://ez.no/doc/ez_publish/technical_manual/4_x/reference/template_operators/data_and_information_extraction/ezhttp
  • ezhttp_hasvariable http://ez.no/doc/ez_publish/technical_manual/4_x/reference/template_operators/data_and_information_extraction/ezhttp_hasvariable (for testing the presence of a GPS variable)

Bear in mind though, that when using this from a node template ( the ones loaded when requesting URLs of the form /content/view/<view_mode>/<node_id> ), view caching is used, increasing performances, but reducing flexibility in some cases. Two solutions, from the top of my head:

  • use the view parameters : .../(my_variable)/value, available through the $view_parameters variables in node templates
  • disable view caching, and add properly keyed cache blocks. This last solution presents the risk of decreasing performances, and should be manipulated with care and proper testing.

Hope it helps,
Let us know how things go,
Cheers !

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Duffy Walsh

Monday 08 March 2010 8:44:38 am

Thank you very much for the reply Nicolas. I am needing to set as well as retrieve so I didn't have much luck with ezhttp. For the view parameters, another part of my problem is that there is a redirect happening, that is making building a url with view parameters difficult.

I did find an extension for session variable handling called SMILE Session. I always make the mistake of not checking the contribs. Thank you again for the concise and quick response!

Regards,

Duffy Walsh

Duffy Walsh