Template operator called many times..

Author Message

Julien JOSEPH-AGATHE

Monday 17 August 2009 12:45:21 am

Hi,

I created a templated opertor called in my pagelayout.tpl (who generate a javascript code for tracking).

When I log when my template operator is call (eZLog::write), i saw 2-5 new lines each time i reload the page... My template operator is call only once in my footer...

I done mu test from http://www.domaine.com/new_siteaccess

The first time, the siteacces return by the function eZSys::indexFile() is the good one (new_siteaccess). But for the second, third,.. it return to me my defaut siteaccess...

I dont understand.

I try to set cookie (with the current siteaccess) before return my js code, but he always return the default..

Someone have a idea to this problem ? Code malformed ? eZ Bug ?

PS: Sorry for my english

Code:

<?php
class test
{
    function test()
    {   
    }

    function operatorList()
    {
        return array(
                        'my_template_operator'
                    );
    }
    function namedParameterPerOperator()
    {
        return array(
                        'my_template_operator'=> array( 'url' )
                    );
    }    
    
    function namedParameterList()
    {
        return array(
                        'my_template_operator' => array(  'params'=> array ())
                    );
    }

    function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
    {
            //parameters initialization
        $arrParemeters = $this->namedParameterList(); 
        foreach ($arrParemeters[$operatorName] as $strNameVar => $arrVal) { 
                
            if (isset($namedParameters[$strNameVar])) {
                    
                $$strNameVar = $namedParameters[$strNameVar];
            } else {
                    
                $$strNameVar = $arrVal['default'];
            }
        }
        switch ( $operatorName )
        {
            case 'my_template_operator':
            {
                 $operatorValue = $this->my_template_operator($params);
                 break;
            }
        }
    }


    function my_template_operator()
    {

       eZLog::write("Siteaccess: " . eZSys::indexFile(), "test.log");

    	$sCode = "<script language=\"javascript\" type=\"text/javascript\">
    	//<![CDATA[
    	*******
        //]]>>
        </script>";
    	
    	return $sCode;
    }
}

?>

Log results:
Siteaccess: new_siteaccess
Siteaccess: defaut_siteaccess
Siteaccess: defaut_siteaccess

Damien Pobel

Monday 17 August 2009 2:59:53 am

Hi Julien,

It's probably because your page uses some missing components (images, CSS, JS, ...) so when you load your page your browser loads two 404 pages that also uses your template operator.

You should check the error.log of the web server or try to use the Network tab of Firebug extension too see what components are missing.

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

André R.

Monday 17 August 2009 4:13:56 am

eZSys::indexFile() is not a function to get current siteaccess, but index file.....
Example on getting current siteaccess name:

$siteAccessName = isset( $GLOBALS['eZCurrentAccess']['name'] ) ? $GLOBALS['eZCurrentAccess']['name'] : null;

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

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