2

In page.tpl.php, I add some static images by using :

$bolo = path_to_theme() . '/images/bolo.gif';
....
<img src="<?php print $bolo ?>" alt="bolo" width="71" height="125">

How I can do the same by using a preprocess function (like theme_image() for example) in template.php and calling the (image)variable in page.tpl.php ? It seems easy, but I can't perform it. Thanks

Bolo

1
  • theme_image() is a theme function. Preprocess functions are things like template_preprocess_html(), template_preprocess_page(), etc. Have you tried doing this in template_preprocess_page(&$vars) and setting $vars['bolo'] = path_to_theme()... and then printing $bolo in your page.tpl? Commented Feb 19, 2013 at 17:01

1 Answer 1

0

You can to use hook_prorocess_page for this.

In the theme's template.php file, add the following function (make sure it doesn't exist. if so, append the function content to the existing file)

function THEMENAME_preprocess_page(&$vars) {
  $image = ... // Generate your image's img tag here, optionally wrap with some DIVs.
  $vars['my_image'] = $image;
}

Now, you can access this variable as $my_image.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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