Pagelayout variable

Author Message

Fou Jino

Tuesday 08 March 2011 7:00:12 am

Hey everyone,

Is that possible to create a variable in pagelayout.tpl and pass this variable to others page across that : {$module_result.content} ??

Thanks in advance !

Foujino ~ http://www.foujino-blog.be

Damien Pobel

Tuesday 08 March 2011 7:17:56 am

Hi,

that's not possible because the pagelayout is computed after the view template. You can do the opposite with the persistent variables mecanism or by using ezpagedata and ezpagedata_set operators if you have the ezwebin extension, see this message http://share.ez.no/forums/developer/add-to-persistent-variable-array#comment63760

Cheers

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Greg McAvoy-Jensen

Tuesday 08 March 2011 7:20:33 am

Fou,

Could you give an example of where you would like to pass the variable to?

Pagelayout.tpl is run after the module, so $module_result is already finished being made before pagelayout is started. You'd need a time machine to pass things into module_result at that point. But pagelayout.tpl variables are certainly available to templates called with the include function.

Granite Horizon, Certified Developer of eZ Publish Web Solutions
Provider of the SaaS Solution Granite Horizon In The Cloud | http://granitehorizon.com/cloud
http://granitehorizon.com | +1 916 647 6350 | California USA | @granitegreg
Blog: http://granitehorizon.com/blog

Fou Jino

Tuesday 08 March 2011 8:29:43 am

Ok, in fact I think that I give you a bad explained

My pagelayout.tpl receive a value that I have to use in others template :

pagelayout.tpl :

[...]

<div id="content">

{$module_result.content}

</div>

[...]

At the level {$module_result.content}, I have for example homepage.tpl :

<div class="my-box">

[...]

{if $var=[...]}

{/if}

[...]

</div>

Thus, I want to give the variable $var from the pagelayout.tpl.

Foujino ~ http://www.foujino-blog.be

Greg McAvoy-Jensen

Tuesday 08 March 2011 8:53:30 am

So you want to set $var is pagelayout.tpl and then read it in homepage.tpl, for example. Is that correct?

Granite Horizon, Certified Developer of eZ Publish Web Solutions
Provider of the SaaS Solution Granite Horizon In The Cloud | http://granitehorizon.com/cloud
http://granitehorizon.com | +1 916 647 6350 | California USA | @granitegreg
Blog: http://granitehorizon.com/blog

Fou Jino

Tuesday 08 March 2011 10:04:31 am

Yes, exactly Greg !

Foujino ~ http://www.foujino-blog.be

Greg McAvoy-Jensen

Tuesday 08 March 2011 12:16:53 pm

Fou,

The technique you describe is impossible. The two process are run serially. The content module is executed, running the full view of the home page, running homepage.tpl. When that module is finished running, it ends, leaving behind $module_result.

Then pagelayout.tpl is executed; all it can do with $module_result.content is display it.

So while it is not possible to pass a variable from pagelayout.tpl to the module which is running, it probably is in fact possible to achieve the end result you desire another way. This is, after all, eZ Publish. So feel free to ask your question again, but describing the end result/user experience needed rather than the coding technique.

Granite Horizon, Certified Developer of eZ Publish Web Solutions
Provider of the SaaS Solution Granite Horizon In The Cloud | http://granitehorizon.com/cloud
http://granitehorizon.com | +1 916 647 6350 | California USA | @granitegreg
Blog: http://granitehorizon.com/blog

Fou Jino

Tuesday 08 March 2011 1:21:27 pm

Aie :(

Ok I have another solution (and question) but it doesn't work :D

I have a module, it initialize a session variable and redirect to racine of my site web

I have 4 differents siteaccess (+ admin siteaccess) in my site and I use this configuration for session variable (in override site.ini)

[Session]

SessionNameHandler=default

SessionNamePerSiteAccess=disabled

So, for example if I am in \en\folder1\object1 and on this page I call my module, my module initialize a session variable and then redirect in \en.

If I show my session variable in \en it's not showed, but if I change the siteaccess for exemple \de, on this siteaccess my session variable showed

And finally, from my pagelayout the session variable is always showed

I don't understand why my session variable is not showed on the siteacces which called my module ??

PS : sorry for my bad english :D

Foujino ~ http://www.foujino-blog.be

Gaetano Giunta

Tuesday 08 March 2011 3:29:49 pm

If this has no security implications, you can often pass data from pagelayout to module templates using a javascript variable.

Principal Consultant International Business
Member of the Community Project Board

Fou Jino

Wednesday 09 March 2011 12:12:53 am

Hi Gaetano,

Yes it's an idea but not very securely, if I have a user with a browser without javascript activated

But I worked with session and I guess that I found why it doesn't work !

In fact, my session configuration was in the site.ini of my extension. Now I add this session configuration in each site.ini of my 4 siteaccess and then I guess it works, I'm trying to test !

And now I'm trying to use session to pass my variable !

Thanks all for your help and for pass your knowledge about pagelayout to me

Foujino ~ http://www.foujino-blog.be

Fou Jino

Wednesday 09 March 2011 12:32:51 am

After testing, I still have a problem ... the session variable is not refreshed and show on the current siteaccess but on others siteaccess it's correctly showed ! :s

Here my session configuration in all siteaccess without admin siteaccess :

[Session]

SessionNameHandler=default

SessionNamePerSiteAccess=disabled

SessionNamePrefix=myapply_

Do you know why ?

Foujino ~ http://www.foujino-blog.be

Fou Jino

Wednesday 09 March 2011 1:42:41 am

I resolve my probleme by disabling the static and view cache :

[ContentSettings]

StaticCache=disabled

ViewCaching=disabled

But I don't know if it's the good solution.

In your opinion ?

Foujino ~ http://www.foujino-blog.be

Gaetano Giunta

Wednesday 09 March 2011 1:27:36 pm

Deactivating the view cache is very bad for performance, and something we always recommend not to do for real-life production sites. If your website only gets a few hundred hits per day, you will not feel the difference, but when traffic explodes, the server will definitely suffer...

Principal Consultant International Business
Member of the Community Project Board

Fou Jino

Wednesday 09 March 2011 2:15:30 pm

Yes I understand but, I don't know why, my session variable it doesn't showed because there is a refresh probleme

If I desactivate the cache, the session variable it correctly refreshed and showed

Foujino ~ http://www.foujino-blog.be

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 04:24:44
Script start
Timing: Jan 18 2025 04:24:44
Module start 'layout'
Timing: Jan 18 2025 04:24:44
Module start 'content'
Timing: Jan 18 2025 04:24:45
Module end 'content'
Timing: Jan 18 2025 04:24:45
Script end

Main resources:

Total runtime1.2465 sec
Peak memory usage4,096.0000 KB
Database Queries95

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0049 592.3828152.6094
Module start 'layout' 0.00490.0027 744.992239.4219
Module start 'content' 0.00761.2377 784.4141752.2031
Module end 'content' 1.24530.0011 1,536.617228.1875
Script end 1.2464  1,564.8047 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00290.2288160.0002
Check MTime0.00120.0942160.0001
Mysql Total
Database connection0.00070.052810.0007
Mysqli_queries1.154892.6498950.0122
Looping result0.00070.0600930.0000
Template Total1.221298.020.6106
Template load0.00190.155720.0010
Template processing1.219297.815020.6096
Template load and register function0.00020.012810.0002
states
state_id_array0.00070.059310.0007
state_identifier_array0.00070.052620.0003
Override
Cache load0.00190.1494890.0000
Sytem overhead
Fetch class attribute can translate value0.00050.039440.0001
Fetch class attribute name0.00160.1244170.0001
XML
Image XML parsing0.00160.130240.0004
class_abstraction
Instantiating content class attribute0.00000.0031200.0000
General
dbfile0.00110.0864300.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
14content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
15content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 38
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs