Drupal 7 - Adding an image to a node.tlp.php theme file

喜欢而已 提交于 2019-12-02 01:29:57

Using drupal_get_path() instead of path_to_theme() may work, worth a shot

<img src="<?php print base_path() . drupal_get_path('theme', 'THEMENAME'); ?>/images/arrow-right.gif" width="20" height="13" alt="Arrow Right">

This was suggested Here

I'm wondering why not us the $directory variable which is available in node.tpl.php file. It was available in Drupal 6 and seems to be working for me for D7 as well.

So code qould be something like:

<img src="/<?php print $directory; ?>/images/arrow-right.gif" width="20" height="13" alt="Arrow Right">

Use the GLOBAL variables array. They are always available because they are, well, global. They are available as an array.

I would just create a new variable in template.php to keep your template files clean:

   // helper variable path to theme
function mytheme_preprocess_node(&$vars) {
$vars['thefullpath'] = $GLOBALS['base_url'] . "/" . $GLOBALS['theme_path'];
}

Then in your template file:

<img src="/<?php print $thefullpath; ?>/images/arrow-right.gif" width="20" height="13" alt="Arrow Right">

Documentation here: http://api.drupal.org/api/drupal/globals/7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!