user2838698
user2838698

Reputation:

How to pass multiple arguments to a smarty function?

I've a following code snippet from smarty template:

<div class="pagination">
  {pagination_link_01 values=$pagination_links}
</div>

The following is the function body:

<?php

function smarty_function_pagination_link_01($params, &$smarty)
{

    if ( !is_array($params['values']) )
    {
      return "is not array";
    }
    if ( 0 == count($params['values']) )
    {
      return "Empty Array";
    }
    if ( empty($params['values']['current_page']) )
    {
      return "Invalid Request";
    }

    $values = $params['values'];

    //Seperator Used Betwinn Pagination Links
    $seprator = empty( $params['seperator'] ) ? "&nbsp;&nbsp;" : $params['seperator'];

    //Class Name For Links
    $extra = empty( $params['extra'] ) ? "" : $params['extra'];

    $current_page  = (int)$values['current_page'];

    if ( !empty($values['first']) )
    {
        //$ret[] = "<a $extra href='{$values['first']}' >&lt;First</a>";
    }
    if ( !empty($values['previous'] ) )
    {
        $ret[] = "<a $extra href='{$values['previous']}' class='prev active'><span></span></a>";                
    }
    $ret[] = "<ul>";
    foreach( $values as $k => $v )
    {
          if( is_numeric( $k ) )
          {
                if ( $k == $current_page)
                {
                    $ret[] = "<li><a $extra class='active'>$k</a></li>";
                }
                else
                {

                    $ret[] = "<li><a $extra href='$v'>$k </a></li>";

                }
          }
    }

    if ( !empty($values['next'] ) )
    {
        $ret[] = "</ul><a $extra href='{$values['next']}' class='next active'><span></span></a>";

    }

    if ( !empty($values['last'] ) )
    {
        //$ret[] = "<a $extra href='{$values['last']}' >Last&gt;</a>";
    }

    //$str_ret = $first . $previous . $str_ret . $next . $last;
    if ( $ret )
    {
        return implode( $seprator, $ret );
    }
}
?>

If I print $params I'm getting the values I passed by means of an array $pagination_links. Similarly I want to add one more argument named $total_pages to the above function call and use it in the function body. I tried many ways but it couldn't happen. Can anyone please guide me in this regard please. Thanks in advance.

Upvotes: 3

Views: 4524

Answers (2)

Borgtex
Borgtex

Reputation: 3245

You call it like this, where $pages is the variable you want to pass:

<div class="pagination">
  {pagination_link_01 values=$pagination_links total_pages=$pages}
</div>

and then in the function

if isset($params['total_pages'])
{
... do something with $params['total_pages']...
}

Upvotes: 2

Panama Jack
Panama Jack

Reputation: 24448

You didn't post much of your code but can't you just pass it to the function?

call your function with your variable. smarty_function_pagination_link_01($params,&$smarty, $total_pages);

e.g.

function smarty_function_pagination_link_01($params, &$smarty, $total_pages)
{

Upvotes: 0

Related Questions