简体   繁体   English

Drupal:使用自定义tpl和变量创建块(渲染数组)

[英]Drupal: Create block with custom tpl and variables (render array)

Goal: 目标:

  • I want to create a block. 我想创建一个块。
  • I want the block to have a tpl file. 我希望该块具有一个tpl文件。
  • I want to pass an array to the tpl for easy "I dont know php" editing. 我想将数组传递给tpl,以便轻松进行“我不知道php”编辑。

In the tpl I want to: 在tpl中,我要:

print render($content['something']);

... instead of just print (render) the entire content all at once: ...而不仅仅是一次打印(呈现)全部内容:

print $content;


Approach so far: 到目前为止的方法:

  • Implement hook_block_info. 实现hook_block_info。
  • Implement hook_block_view and set $block['content'] to a function which returns a renderable array. 实现hook_block_view并将$ block ['content']设置为一个返回可渲染数组的函数。
  • Create the right block_ .tpl file and print $content['something']. 创建正确的block_ .tpl文件并打印$ content ['something']。
  • Error :( 错误:(

Now, I can make this work by implementing hook_theme, but I would love to just use the default block_ .tpl. 现在,我可以通过实现hook_theme来完成这项工作,但是我只想使用默认的block_ .tpl。 Am I doing something wrong? 难道我做错了什么?

In the .tpl you can do: 在.tpl中,您可以执行以下操作:

print render($elements['something']);

wee! e!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM