Add to persistent variable array

Author Message

paul bolger

Wednesday 17 November 2010 10:42:29 pm

I'm using the ezgmaplocation extension to add a map to a page, but ran into a problem trying to simultaneously use the jqueryui accordion - the accordion wouldn't work properly with the link to the Google javascript where it was, so I had to move it up into the page head.

I found that setting the Javacript link as the persistent variable (from the ezgmaplocation template) was pretty easy but that wiped out the other values in the persistent variable array. I tried using the merge function to add it to the array, but have had no luck getting it to work. Is this the right approach, or would I be better off trying something else?

Paul Bolger

Carlos Revillo

Thursday 18 November 2010 11:51:59 am

hi. don't know if i'm missing something, but i think you can take a look to the ezpagedata_set operator...

paul bolger

Sunday 21 November 2010 3:01:30 am

Thanks Carlos, That looks promising, but there doesn't seem to be any documentation. An example of usage would be appreciated.

Paul Bolger

Carlos Revillo

Sunday 21 November 2010 4:25:01 am

Example is simple.

Having a node/view/full.tpl template or an override of it, or even an error page, you can do in that template something like

{ezpagedata_set( 'var1', 89 )}

you can get that variable in pagelayout like

{def $pagedata = ezpagedata()}
Var 1 is: {$pagedata.persistent_variable.var1}

Gaetano Giunta

Sunday 21 November 2010 5:14:52 am

Carlos example is fine. Otoh using merge and plain arrays to add more stuff to the persistent variable from templates should be fine too.

@Paul: can you show the exact code that you have and does not work?

Principal Consultant International Business
Member of the Community Project Board

paul bolger

Sunday 21 November 2010 5:31:59 pm

@Carlos: Thanks, that did it. Here's what I did (for the benefit of others).

My problem was that the js - the one with the key in it - link in ezgmaplocation was causing problems with other js on the page. Manually moving it around confirmed that moving it into the page head fixes the problem. But of course changing a line in one of the pagelayout templates to suit an extension is not good practice.

Initially I tried using the merge array function (@Gaetano: this is what I was talking about)

http://doc.ez.no/doc/eZ-Publish/Technical-manual/4.x/Reference/Template-operators/Arrays/merge

with no luck.

So here's what worked:

I added this to the ezgmaplocation.tpl (override, of course)

{def $mapkey=ezini('SiteSettings','GMapsKey')}
{def $jslinkstart='<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='}
{def $jslinkend='" type="text/javascript"></script>'}
{def $googlemapslink=concat($jslinkstart,$mapkey,$jslinkend)}
{ezpagedata_set('script_list', array( $googlemapslink ))}

Then I added this to the beginning of page_head_script.tpl

{if and( is_set( $pagedata.persistent_variable.script_list ), $pagedata.persistent_variable.script_list|count() )}
{foreach $pagedata.persistent_variable.script_list as $extra_script}
{$extra_script}
{/foreach}

There are two drawbacks I can see with this. One is that a future change to page_head_script.tpl could cause problems (ie the overridden version wouldn't reflect the changes). and two, if one were to use this method across a few extensions they would all become interdependent - breaking or removing one would break the rest.

See this page for a bit more info.

http://share.ez.no/forums/developer/smart-loading-of-javascript

Paul Bolger

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 10:41:07
Script start
Timing: Jan 18 2025 10:41:07
Module start 'layout'
Timing: Jan 18 2025 10:41:07
Module start 'content'
Timing: Jan 18 2025 10:41:08
Module end 'content'
Timing: Jan 18 2025 10:41:08
Script end

Main resources:

Total runtime0.8134 sec
Peak memory usage4,096.0000 KB
Database Queries68

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0070 589.0547152.6250
Module start 'layout' 0.00700.0034 741.679739.4531
Module start 'content' 0.01040.8014 781.1328615.9297
Module end 'content' 0.81170.0017 1,397.062516.1563
Script end 0.8134  1,413.2188 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.4164160.0002
Check MTime0.00130.1601160.0001
Mysql Total
Database connection0.00120.142110.0012
Mysqli_queries0.748091.9506680.0110
Looping result0.00070.0855660.0000
Template Total0.780796.020.3904
Template load0.00220.272020.0011
Template processing0.778595.704520.3892
Template load and register function0.00010.012710.0001
states
state_id_array0.00090.105510.0009
state_identifier_array0.00070.087820.0004
Override
Cache load0.00190.2379360.0001
Sytem overhead
Fetch class attribute can translate value0.00080.096130.0003
Fetch class attribute name0.00140.166280.0002
XML
Image XML parsing0.00110.140430.0004
class_abstraction
Instantiating content class attribute0.00000.0023100.0000
General
dbfile0.00090.1101220.0000
String conversion0.00000.001140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs