如何在 Drupal 7 主题中向硬编码图像添加属性


How to add attributes to hard coded images in Drupal 7 themes

我正在使用

<?php echo theme('image', array('path' => drupal_get_path('theme', 'themename') .'/img/demo.png')); ?>

将图像硬编码到我的Drupal 7主题中。 我的问题是如何添加"id"、"类"或"alt"等属性?

要添加额外的属性,请传递具有必要key => value对的数组attributes。与alt属性相同。

例如:

print theme('image', array(
    'path' => drupal_get_path('theme', 'themename') . '/img/demo.png',
    'alt' => 'my alt content',
    'attributes' => array(
        'id' => 'myId',
        'class' => 'myClass',
    ))
);