THEME_preprocess_image和THEME_image之间的区别?

时间:2015-08-19 16:25:29

标签: drupal-theming

这两个函数之间有什么区别,可以放在drupal的template.php中?

function THEME_preprocess_image(&$variables) {
    // something
}

function THEME_image($variables) {
    // something
}

1 个答案:

答案 0 :(得分:1)

function theme_image呈现可渲染数组的HTML输出。

  

THEME_preprocess_image

我相信,正确的名称是template_preprocess_HOOK,它在主题函数之前在theme()内部调用,例如。 THEME_image

请在此处考虑用例:

// In custom.module     
$variables = array( 
  'path' => 'path/to/img.jpg', 
  'alt' => 'Test alt',
  'title' => 'Test title',
  'width' => '50%',
  'height' => '50%',
  'attributes' => array('class' => 'some-img', 'id' => 'my-img'),
  );
$img = theme('image', $variables);

如果要更改图像的某些属性,请执行以下操作:

function mytheme_preprocess_image($vars) {
    // Do the changes, before it's rendered.
}