Path

ez projects / ezjscore / forum / general / ezscript_require removes pe...


ezscript_require removes persistent_vars set in pagelayout?

You need to be logged in to post messages in the forums. New users may register here.

STEVO +

Member since:
09 January 2008

Posts: 23

Saturday 19 September 2009 6:22:09 pm

hi,

it seems when i use ezscript_require it stores the file list in $persistent_variables but also removes all other keys in the array that are set after $module_result.

can someone verify this and/or explain if this is intended.

cheers!
Up

André R

Member since:
20 August 2005

Posts: 171

Sunday 20 September 2009 10:33:17 pm

Could you give an example?

There is a slight bug in there that I'll fix tomorrow, in that it reads value from $module_result.content_info.persistent_variable and writes the changes back to $persistent_variable. It should probably not write changes back at all in pagelayout though, since we can't guarantee that the value survives across different cache-blocks, what do you think?
Is that the one?

Other then that it will wipe the value if it isn't an array ( hash() ), I'll also add a error in that case and mention it in the requirement section of the doc.

--
ar

Up

STEVO +

Member since:
09 January 2008

Posts: 23

Tuesday 22 September 2009 11:28:05 pm

well, i have to say, i'm confused as all hell.

it's r44 and above that's breaking my code.

i'm using ezpagedata() with ezwebin 1.4

in pagelayout.tpl if i do the following (after using ezscript_require):
{ezpagedata_set('test', 'testVal')}


                {def $pagedata=ezpagedata()}


                {$pagedata.persistent_variable|attribute(show)}


only the js_files + css_files keys are there.

any enlightenment at all about all this $persistant_variables matter, greatly appreciated

thanks andre
Up

André R

Member since:
20 August 2005

Posts: 171

Wednesday 23 September 2009 12:50:19 am

Ok, I'll test it tomorrow, thanks for the test case.

But, if 44 broke your code, what issue did you first experience? (as that was done after your first post)

--
ar

Up

STEVO +

Member since:
09 January 2008

Posts: 23

Wednesday 23 September 2009 1:08:01 am

blimey, replying at this hour, i'm honoured :)

good point, i told you i was confused!

well, i've just been through the revisions that change ezjscpackertemplatefunctions.php down to 18 + they work. i'm baffled.

Up

STEVO +

Member since:
09 January 2008

Posts: 23

Wednesday 23 September 2009 1:35:25 am

ack, in 43 only because any ezpagedata_set removes the js_files + css_files keys.
Up

STEVO +

Member since:
09 January 2008

Posts: 23

Wednesday 23 September 2009 1:55:49 am

another thought, the template code i'm using is within a {node_view_gui} call from pagelayout.tpl
Up

André R

Member since:
20 August 2005

Posts: 171

Wednesday 23 September 2009 11:08:38 am

Seems like all of these functions desperately needs some documentation.

Some tests, in pagelayout:



{ezscript_require('somescript.js')}


{ezpagedata_set('test', 'testVal')}


{def $pagedata = ezpagedata()}


 

{$pagedata.persistent_variable|attribute('show', 1)}




Gives:



Attribute       Type    Value


left_menu       boolean         false


extra_menu      boolean         false


show_path       boolean         false


js_files        array   Array(1)



This is expected since ezpagedata_set and ezpagedata_append is not intended for use in pagelayout (they do not use $module_result.content_info.persistent_variable).

As for your case, in node template in pagelayout using {node_view_gui} directly in pagelayout.tpl:



{node_view_gui view=line content_node=fetch('content', 'node', hash('node_id', 43))}



Folder line view node template:



{ezscript_require('somescript.js')}


{ezpagedata_set('test', 'testVal')}


{def $pagedata        = ezpagedata()}


{$pagedata.persistent_variable|attribute('show', 2)}



Gives:



Attribute       Type    Value


left_menu       boolean         false


extra_menu      boolean         false


show_path       boolean         false


css_files       array   Array(7)


>0   string  'core.css'


>1   string  'debug.css'


>2   string  'pagelayout.css'


>3   string  'content.css'


>4   string  'websitetoolbar.css'


>5   string  'yui/build/calendar/assets/calendar.css'


>6   string  'ezfind.css'


js_files        array   Array(8)


>0   string  'tools/ezjsselection.js'


>1   string  'insertmedia.js'


>2   string  'yui/build/yahoo-dom-event/yahoo-dom-event.js'


>3   string  'yui/build/calendar/calendar-min.js'


>4   string  'ezdatepicker.js'


>5   string  'yui/2.5.2/build/utilities/utilities.js'


>6   string  'classlists.js'


>7   string  'somescript.js'



Still as expected since ezpagedata_[set|append] (uses $persistent_variable) does not support being in pagelayout and ezpagedata() (uses $module_result.content_info.persistent_variable) is not ment to be used in node templates.

Same code in rev 38 gives:



Attribute       Type    Value


left_menu       boolean         false


extra_menu      boolean         false


show_path       boolean         false



Witch I would say is a bit wrong.

--
ar

Up

André R

Member since:
20 August 2005

Posts: 171

Wednesday 23 September 2009 11:13:23 am

Ahh, this is not on a node, this is on a module where content_info is not set, like user/login.

Last code example gives me this on user/login with rev 38:



Attribute       Type    Value


css_files       array   Array(6)


>0   string  'core.css'


>1   string  'debug.css'


>2   string  'pagelayout.css'


>3   string  'content.css'


>4   string  'websitetoolbar.css'


>5   array   Array(2)


js_files        array   Array(8)


>0   string  'tools/ezjsselection.js'


>1   string  'insertmedia.js'


>2   string  'yui/build/yahoo-dom-event/yahoo-dom-event.js'


>3   string  'yui/build/calendar/calendar-min.js'


>4   string  'ezdatepicker.js'


>5   string  'yui/2.5.2/build/utilities/utilities.js'


>6   string  'classlists.js'


>7   string  'somescript.js'


test    string  'testVal'




And this with 47:



Attribute       Type    Value


test    string  'testVal'





This is actually also as expected, since the result in 38 that makes it look correct is caused by the bug where it defined $persistent_variable even if this isn't really a true node template.
Where it in 47 instead uses it's internal $persistentVariable php variable which is not shared between eZPageData (ezwebin) and ezjscPackerTemplateFunctions (ezjscore) at the moment.

In other words, you can't expect to get the script files by calling ezpagedata() at the moment. This is what ezscript_load() is for, it loads the scripts defined when calling ezscript_require().

So maybe we should turn the table, what do you try to do with your code?

--
ar

Up

STEVO +

Member since:
09 January 2008

Posts: 23

Wednesday 23 September 2009 3:02:58 pm

> Seems like all of these functions desperately needs some documentation.

big time!

so it looks like i've been caught out by a bug that happened to make what i was doing work previously

basically, i have some node/view templates that are sometimes called from the content/view module + sometimes from pagelayout. it's time for some serious refactoring.

thanks loads for your time, sorry for the bother
Up

André R

Member since:
20 August 2005

Posts: 171

Wednesday 23 September 2009 4:27:13 pm

Ok, since you didn't explain the use case, consider this (might help in your refactoring):

eZ Publish execution order:

* view template (node / user/login and so on):



{ezscript_require( 'script1.js' )}



Stores the value in persistent_variables or on internal variable (make sure its not inside a cache-block, and don't do it conditionally unless view is uncached or the conditions are part of the view cache hash).

* pagelayout <head>:



{ezscript_load( 'script2.js' )}



Loads script2.js and script1.js (yes, in that order as input for _load is used for global scripts) and marks javascripts as loaded.

* Inline node view in pagelayout:



{ezscript_require( array( 'script1.js', 'script3.js' ) )}



Loads script3.js straight aways as it sees that _load() has already been executed (unless this is another cache-block that executes un parallel with the one _load() is in ), and that script1.js has already been loaded.

--
ar

Up

You need to be logged in to post messages in the forums. New users may register here.