【问题标题】:Drupal 7 - Where can I find templates for render() function?Drupal 7 - 我在哪里可以找到 render() 函数的模板?
【发布时间】:2011-03-15 06:26:42
【问题描述】:

当我为节点创建自定义模板时,我发现 Drupal 添加了额外的 html。

所以我改变了 page.tpl.php 如下所示来测试

<div style='height:300px'>
  <?php print render($page['content']); ?>
</div>

然后把node.tpl.php改成

hello

输出是:

<div style='height:300px'> 
    <div class="region region-content"> 
    <div id="block-system-main" class="block block-system"> 


  <div class="content"> 
    hello  </div> 
</div> 
  </div> 
</div> 

所有这些额外的标签是从哪里来的?

其实我期待&lt;div style='height:300px'&gt;hello&lt;/div&gt;

【问题讨论】:

  • 转到管理->结构->块->点击内容上的“配置”->为您的主题选择“无”
  • 您真的不想这样做,这会完全从您的主题中删除主要内容。例如,如果你在管理主题上这样做,你将无法取回它......

标签: drupal themes


【解决方案1】:

drupal_render() 可用于渲染所谓的可渲染数组。这些是自包含的,它们告诉 render() 使用哪个主题函数/模板。

试试 dpm($page['content']),它应该有一个包含该信息的“#theme”键。

【讨论】:

    【解决方案2】:

    一个不错的 dpm。 要打印 h2 和正文,您可以在 page.tpl.php 中编写类似这样的内容。

    <?php print render($page['content']['system_main']['nodes'][1]); ?></div> ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多