Solution: How to add view parameter support to your custom module view

Have you ever wanted to add view parameter support to your custom module view templates?

Example Solution #1

Here is a quicker way to add view parameters. Simply add this snippet of php into your custom module view.

// Set the view parameters
$tpl->setVariable( 'view_parameters', $Params['UserParameters'] );

Place the above PHP snippet code before you include your primary module view template within $Result['content'].

/**
  * Prepare module view content results for display to user
  */
$Result['content'] = $tpl->fetch( 'design:custom-module/create.tpl' );
 

Example Solution #2

Here is a longer form way to view parameters. Simply add this snippet of php into your custom module view.

// Set the view parameters
$viewParameters = array();
$uri = eZURI::instance( eZSys::requestURI() );
$uriUserParameters = $uri->userParameters();
 
foreach( $uriUserParameters as $key => $param )
{
    if( $param != '' )
    {
        $viewParameters = array_merge( $viewParameters, array( $key => $param ) );
    }
}
 
if( $tpl->hasVariable( 'view_parameters' ) )
{
    $viewParameters = array_merge( $tpl->variable( 'view_parameters' ), $viewParameters );
}
 
$tpl->setVariable( 'view_parameters', $viewParameters );
 
 

Place the above PHP snippet code before you include your primary module view template within $Result['content'].

/**
  * Prepare module view content results for display to user
  */
$Result['content'] = $tpl->fetch( 'design:custom-module/create.tpl' );