eZ Community » Forums » Developer » persistent_variable unveiled
expandshrink

persistent_variable unveiled

persistent_variable unveiled

Friday 13 January 2012 5:01:38 pm - 4 replies

Hi there,
just because it took me a while to understand how to work with the persistent_variable, I want to share the knowledge.
Usually you need persistent_variable if you want to pass a value from a template in node context to one in the pagelayout context. But some other extension might already use the variable, so you should not overwrite it.
If the persistent_variable is a hash you just can modify it in node context with.

 {set scope=global $persistent_variable = $#persistent_variable | merge(hash('key', 'value')) }

This just adds a new key/value pair to it. It is important to use scope=global to set it and $# to access the old value in global scope.
It is easy to acces it in pagelayout context then

 {$module_result.content_info.persistent_variable.key}

If you are writing an operator in PHP you can access and modify it in node context with:

$persistent_variable = array();
if($tpl->hasVariable('persistent_variable'))
    $persistent_variable = $tpl->variable('persistent_variable');
$persistent_variable['key'] = 'value';
$tpl->setVariable('persistent_variable', $persistent_variable);

And in in pagelayout context with:

$module_result = $tpl->variable('module_result');
$persistent_variable = array();
if(isset($module_result['content_info']['persistent_variable']))
  $persistent_variable = $module_result['content_info']['persistent_variable'];

Kai

Saturday 14 January 2012 10:39:48 am

Hello Kai,

 

Welcome to the eZ Community!

 

Thank you for sharing with the other users in the community.

I think it's great what you have done and urge other users to take your example to heart themselves. We need more users who share solutions between each other and helping each other reach our common goals.

If I might, I would suggest you create a share.ez.no blog (login and check your profile page to do this; free to all) and post this solution as a blog post. I would also encourage you to post this solution specifically in http://eZpedia.org so that it is easy to find and use this solution in the future.

See I suggest these alternatives because in practice, as others have said previously, solutions shared only in forum threads are more often the hardest to find if you don't know exactly what your looking for beforehand. By posting your solutions only in forum threads your contributions and potential to help with your solutions are ... in a way diminished when they are not found or read, virtually buried in a sea of older forum posts.

By posting documentation like this in with other real documentation just like it .. as in the case with eZpedia, your documentation contributions elivated above forum posts and organized and maintained (on your behalf of the community) I feel this increases greatly the value of your documentation contributions as they are read, they are easily found many ways and spcifically not burried as forum threads are. http://eZpedia.org is free for all to edit and use to post even small pages of documentation and registering for an account is also free and fairly simple, In minutes you'll be able to edit almost all content in the site but you can start by creating your own article in the 'solutions' folder, then simply paste your forum thread text and publish the article and your done.

 

Or if you don't mind, I would be happy to create the page in http://eZpedia.org on this topic on your behalf and share a link to it here. You could also edit this page yourself later if you prefer a change to it at any time).

Apologies if I ask to much. I merely try to see what would happen in the future if more steps are not taken to protect the investment to the community (there is no such thing is too small in my view) and ensure it's value grows instead of diminishes over the course of time.

eZ Publish in it's current form has been around for a very long time and remained mostly compatible with written documentation thus far. I imagine that properly protected on eZpedia your contributions could help people well into the future. How does this find you?

 

I hope this helps ...

 

Cheers,

Heath

Sunday 15 January 2012 9:40:01 pm

Hello Kai,

 

We took some time this weekend a wrote a new page on eZpedia which covers the solution documentation you share here in the forum.

For those interested, please feel free to read and edit this slightly more clear and understandable documentation on the topic in question.

http://ezpedia.org/ez/persistent_template_variables

 

Cheers,

Heath

Tuesday 17 January 2012 11:32:58 am

Hello Heath,

great work! Thanks a lot. And you're definitely right, that the post belongs to a wiki or a blog. I'am quite new to eZ Publish and the forum was first place I found. I'am glad that my post now found it's right place so quickly.

Regards
Kai

Wednesday 18 January 2012 5:33:46 am

Hello Kai,

 

Thank you for your kind words. It's nothing that special.

I merely do what a majority of others all around me continue to refuse to do. Specifically, the work that makes long term positive impacts for all users world wide.

Sometimes it's fun, other days it can ... for a short time feel like a burden. It's posts like yours that remind me to not focus on the less positive interactions and keep striving to help the next user even better than what was possible with the last.

 

You know Kai, Right now I think the think that what really makes the most difference for folks like myself is support. I can't begin to tell you the number of threads we have made entries for and no one noticed or cared. So ... I personally really apreciate the very nature of your latest responces and the responces themselves are great to hear at the end of yet another very long very trying day.

 

So again, I thank you for your support and enthusiasm!

 

It's almost even more fantastic that a newer user is so interested in sharing with the community so quickly or as my boss would put it, 'Promptly'.

There are a lot of different sources for information in the eZ Community.

You found the most important one first. I just know you'll grow to learn to navigate your way through towards success.

 

If you like to continue sharing (perhaps in a more effective way as we are discussing), consider creating a share.ez.no blog (login and see the button to create this on your profile page).

Just know that today there is no direct way to read blog posts in the same order they were published after the latest 5 blog posts today content drops off the home page. So the blogs are a little weak in terms of support. I hope this can be addressed in the future. Worth noting is that you can actually search for blog content as an undocumented alternative.

 

And lastly I would also welcome you to create an account on eZpedia and feel free to see just how quick and simple it is to post documentation on eZpedia yourself. With eZpedia all our content stored in categories and each category has a corresponding list of all content contained without limitations. This means content is always listed clearly and consistently with no chance of your changes of being 'lost' or not found at some point.

Some people create a 'person' page to practice using the editor and site features in a limited way. Again this is merely a couple of suggestions.

 

I only wish to encourage you and help you to reach the best possible outcome with the available solutions at our disposal and I'm only taking time to mention the two most relevant there are many other possibilities imaginable. 

 

I think I've mentioned the blogs issue at least twice previously here in the forums. In the interest of ensuring I don't make the mistake I've seen in other more recent threads this will be the last time I introduce the topic in an explanation.

Until I've had time to confer with the rest of my team and seek to help make the changes needed to the share.ez.no related blog templates to address the matter once and for all (apparently the ideas are already discussed and i'm late to the discussion today XD ). More as it happens ...

 

Thanks again for your support of community documentation and our work. Your support is ultimately what drives us to continue to do what's right for the next guy to come behind me, without betraying too my own self interests of being able to afford to eat today :\

 

Take care Kai and please feel free to ask questions here in the forums any time happy.gif Emoticon

 

Cheers,

Heath

Modified on Wednesday 18 January 2012 5:35:14 am by // Heath

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from