Forums / Developer / Custom tpl operator parameter ?

Custom tpl operator parameter ?

Author Message

H-Works Agency

Saturday 14 January 2006 6:53:30 am

I have a problem with my custom template operator 'age'.

It is only working when passing the parameter like this : {age(parameter)}
But not like this, as it should be : {parameter|age}

What can make it act so ?

I based my work on the creating custom operator extension document :
http://ez.no/products/ez_publish_cms/documentation/development/extensions/template_operator

Martin

EZP is Great

Norman Leutner

Sunday 15 January 2006 1:08:43 am

What about posting your code here?

here a small example:

<?php

class FakePriceOperators
{
    /*!
     Constructor
    */
    function FakePriceOperators()
    {
        $this->Operators = array( 'fake_price');
    }

    /*!
     Returns the operators in this class.
    */
    function &operatorList()
    {
        return $this->Operators;
    }

    /*!
     \return true to tell the template engine that the parameter list
    exists per operator type, this is needed for operator classes
    that have multiple operators.
    */
    function namedParameterPerOperator()
    {
        return true;
    }

    /*!
     The first operator has two parameters, the other has none.
     See eZTemplateOperator::namedParameterList()
    */
    function namedParameterList()
    {
        return array( 'fake_price' => array( 'fake_percent' => array( 'type' => 'string',
                                                                 'required' => false,
                                                                 'default' => '20' ) ) );
    }

    /*!
     Executes the needed operator(s).
     Checks operator names, and calls the appropriate functions.
    */
    function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace,
                     &$currentNamespace, &$operatorValue, &$namedParameters )
    {
        switch ( $operatorName )
        {
            case 'fake_price':
            {
                $operatorValue = $operatorValue * (100 - $namedParameters['fake_percent']) / 100;
            } break;
        }
    }

    /// \privatesection
    var $Operators;
}

?>

Seems like:

    function namedParameterList()
    {
        return array( 'fake_price' => array( 'fake_percent' => array( 'type' => 'string',
                                                                 'required' => false,
                                                                 'default' => '20' ) ) );
    }

Is missing in your extension.

Mit freundlichen Grüßen
Best regards

Norman Leutner

____________________________________________________________
eZ Publish Platinum Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh