kia*_*uno 13
使用Drupal 7,您只需要实现hook_preprocess_image(),因为为每个主题函数执行预处理函数,而不仅仅是使用模板文件的函数.在您的情况下,以下代码应该足够了.
function mymodule_preprocess_image(&$variables) {
foreach (array('width', 'height') as $key) {
unset($variables[$key]);
}
}
Run Code Online (Sandbox Code Playgroud)
由于$variables['attributes']还包含图像属性,以下代码更加完整.
function mymodule_preprocess_image(&$variables) {
$attributes = &$variables['attributes'];
foreach (array('width', 'height') as $key) {
unset($attributes[$key]);
unset($variables[$key]);
}
}
Run Code Online (Sandbox Code Playgroud)
将mymodule替换为模块/主题的简称.
当您需要更改传递给主题函数/模板文件的变量时,首选预处理函数.仅当您需要更改它们返回的输出时,才应覆盖主题函数.在这种情况下,您只需要更改变量,因此不必覆盖主题函数.使用预处理钩子,您的代码将与未来的Drupal版本兼容.
| 归档时间: |
|
| 查看次数: |
5397 次 |
| 最近记录: |