【问题标题】:how to display images in the page.tpl.php with drupal 7 [closed]如何使用drupal 7在page.tpl.php中显示图像[关闭]
【发布时间】:2013-04-07 09:55:55
【问题描述】:

我的主题是名称(汽车),并且在 page.tpl.php 中有图像链接,我想用简短的方式显示此图像 任何人都可以帮助我..node.tpl.php 的大部分方法,但我需要用 page.tpl.php 显示图像

<img src="rightgallery/img/img1_thumb.jpg" alt="motherly" /> 

我尝试将此代码添加到 template.php 文件中

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

然后像这样打印路径但还是不行

<img src="<?php print $thefullpath; ?>rightgallery/img/img1_thumb.jpg"  alt="motherly"

>

【问题讨论】:

  • 最后一次 sn-p 的输出是什么?

标签: php drupal drupal-7 drupal-theming


【解决方案1】:

实际上有两种方法可以直接从你的主题的 page.tpl.php 中执行此操作(无需创建模板预处理函数):

1- 使用&lt;img&gt; 标签:

global $base_path;
print "<img src='" . $base_path . path_to_theme() . "/img/img5.jpg' width='240' height='300' />";

2- 使用 Drupal 的 theme():

print theme("image", array(
    'path'  => path_to_theme() . "'/img/img5.jpg",
    'width' => "240",
    'height' => "300",
));

参考资料:

【讨论】:

    【解决方案2】:

    这样的正确路径

    <li>
      <img src="<?php print  $thefullpath; ?>/rightgallery/img/img5.jpg" 
         alt="nature sent packing" width="240" height="300" />
    </li>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多