如何在 Drupal 表单中拥有一个区域

发布于 2024-09-25 08:25:57 字数 450 浏览 5 评论 0原文

我正在尝试修改 drupal 评论表单,以便在表单上方我可以显示一个区域并向该区域添加更多块(比如一些促销横幅)。

我在 template.php 中这样做 我有一个有效的 themename_comment_form 函数,可以将 $form['intro']['#value'] 设置为我想要的值。我也知道如何创建一个新区域。

我正在努力获取该区域的值(例如 $above_comment_form)并使其在 themename_comment_form 中可用(类似于 $form['intro']['#value'] = $above_comment_form;) 我尝试过 preprocess_page, preprocess_node 设置像 $vars['above_comment_form']=$above_comment_form 这样的值,但没有运气。

I am trying to modify drupal comment form so that just above the the form I can show a regions and add more blocks to that region (say some promotional banners).

I am doing this in template.php
I have a working themename_comment_form function and can set $form['intro']['#value'] to the value I want. I also know how to create a new region.

What I am struggling is to get the value of that region (say $above_comment_form) and make it available inside themename_comment_form (something like $form['intro']['#value'] = $above_comment_form;)
I have tried preprocess_page, preprocess_node to set the value like $vars['above_comment_form']=$above_comment_form but no luck.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坏尐絯 2024-10-02 08:25:57

要创建区域,您需要将其添加到模块的 .info 文件中。如果您没有定义任何区域,则默认有 5 个可用区域:

  • left
  • right
  • content
  • header
  • footer

如果您想添加/删除区域,您需要在您的文件中写入全部您想要的区域。主题。因此,要包含自定义区域,您需要将其添加到 .info 文件中:

regions[header] = "Header"
regions[left] = "Left sidebar"
regions[content] = "Content"
regions[right] = "Right sidebar"
regions[footer] = "Footer"
regions[above_comment_form] = "Above the comment form"

现在默认情况下,区域仅在 page.tpl.php 中可用。您可以使用 theme_blocks 获取用户可用的区域中的块。因此,在您的 preprocess_node 函数中,您需要添加:

$vars['above_comment_form'] = theme('blocks', 'above_comment_form');

然后在您的 node.tpl.php 中,您可以执行以下操作:

<div id="above_comment_form">
  <?php print $above_comment_form; ?>
</div>

这应该完成您的任务。

To create a region, you need to add it in your module's .info file. If you don't have any regions defined, the default is to have 5 available:

  • left
  • right
  • content
  • header
  • footer

If you want to add/remove regions you will need to write all the regions you want in your theme. So to include the custom region you would need to have this in your .info file:

regions[header] = "Header"
regions[left] = "Left sidebar"
regions[content] = "Content"
regions[right] = "Right sidebar"
regions[footer] = "Footer"
regions[above_comment_form] = "Above the comment form"

Now regions are only available in your page.tpl.php by default. You can get the blocks in a region that's available to the user by using theme_blocks. So in your preprocess_nodefunction you would need to add:

$vars['above_comment_form'] = theme('blocks', 'above_comment_form');

Then in your node.tpl.php you can do this:

<div id="above_comment_form">
  <?php print $above_comment_form; ?>
</div>

That should accomplish your task.

爱人如己 2024-10-02 08:25:57

区域的渲染在调用堆栈中发生得很晚,因此大多数时候不可能将它们包含在主题函数或 form_alter 等内容中。

但是,您可以在其中渲染单个块,因此,如果您希望使用以下内容添加特定块:

$block = module_invoke('block', 'block', 'view', 26);
print $block['content'];

这将在主题函数和模板中工作。我尝试做一些类似的事情,并在页面渲染中深入挖掘以查找渲染区域的函数,但尝试在堆栈中较早地渲染区域要么是不可能的,要么不值得。

The rendering of regions happens very late in the call stack so most times it is not possible to include them in something like a theme function or a form_alter.

However you can render individual blocks in those, so if you are looking to add a specific block using something like:

$block = module_invoke('block', 'block', 'view', 26);
print $block['content'];

Which will work in theme functions and templates. I tried doing something simular and dug pretty deep in the page rendering to look for the functions that rendered the regions, and it was either not possible, or not worth it to try to render the region earlier in the stack.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文