1

Is it possible to include markup in the $text variable of theme_pager_next()? I find that whatever I set the variable to gets output as a string, rather than being rendered as HTML. Here's some example code as would be found in template.php:

    function theme_pager_next($variables){ 
      $text = '<span>test value</span>';

      /* Remainder of function call goes here ...*/

      return $output;
    }

I would like be able to add an image to the pager text. I realize I could also use CSS background images, but would prefer to print markup to the page if at all possible.

Is there something I'm overlooking?

  • I think we'll need to see the remainder of the function. – jdu Aug 3 '12 at 17:01
1

If the rest of the code is the same used in theme_pager_next(), then it is not possible to add HTML tags to $text.

This is because theme_pager_next(), and theme_pager_last() call theme_pager_link(). theme_pager_next()'s code is the following one.

if ($page_new[$element] == ($pager_total[$element] - 1)) {
  $output = theme('pager_last', array('text' => $text, 'element' => $element, 'parameters' => $parameters));
}
// The next page is not the last page.
else {
  $output = theme('pager_link', array('text' => $text, 'page_new' => $page_new, 'element' => $element, 'parameters' => $parameters));
}

theme_pager_link() then contains the following code.

$attributes['href'] = url($_GET['q'], array('query' => $query));
return '<a' . drupal_attributes($attributes) . '>' . check_plain($text) . '</a>';

As it calls check_plain(), if $text contains HTML tags, they are shown as plain text.

To achieve what you are trying to do, you should override theme_pager_link() with a theme function that doesn't call check_plain(). filter_xss() could be a better function to use in this case, but remember to pass in $allowed_tags the list of the tags you want to allow.

As side note, when you want to alter the content of the $variables array a theme function gets, in Drupal 7 you can use its preprocess functions. Every theme function has preprocess functions, and in your theme that is THEME_preprocess_pager_next(). (Replace THEME with the short name of your theme.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.