包含 1 个以上内容项的内容块

发布于 2024-10-21 16:57:30 字数 508 浏览 4 评论 0原文

以下代码是用 php 制作的 Drupal 块。
1)我如何实现多个项目?现在我有 test1,但我想要 test1、test2、test3 和 test5。
2)我如何将标题(例如 test1)链接到我的管理/设置/菜单?我想将一个项目链接到 Drupal 中的 node_import。

function planning_block($op='list', $delta=0, $edit=array()) {
  switch ($op) {
    case 'list':
        $blocks[0]['info'] = t('Stage administration block');
        return $blocks;
    case 'view':
        $blocks['subject'] = t('Stage administratie');
        $blocks['content'] = 'test';
        return $blocks;
  }
}

The following code is a Drupal block made in php.
1) How can I implement more then one item? now i have test1 but i want test1, test2, test3 and test5.
2) how can i link a title for example test1 to my admin/settings/ menu? I want to link an item to node_import in Drupal.

function planning_block($op='list', $delta=0, $edit=array()) {
  switch ($op) {
    case 'list':
        $blocks[0]['info'] = t('Stage administration block');
        return $blocks;
    case 'view':
        $blocks['subject'] = t('Stage administratie');
        $blocks['content'] = 'test';
        return $blocks;
  }
}

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

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

发布评论

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

评论(2

塔塔猫 2024-10-28 16:57:30

如果您参考 hook_block 的文档< /a>,你可以在一个钩子内声明多个块。

$delta 参数可以帮助您区分正在渲染的块。

关于标题中的链接,只需在设置 $block['subject'] 值时使用 l() 函数即可。

例子:

function planning_block($op='list', $delta=0, $edit=array()) {
  switch ($op) {
    case 'list':
      $blocks[0]['info'] = t('Stage administration block 1');
      $blocks[1]['info'] = t('Stage administration block 2');
      return $blocks;
    case 'view':
      switch ($delta) {
        case 0:
          $blocks['subject'] = t('Stage administratie');
          $items = array(
            l('Item 1', 'admin/settings/1'),
            l('Item 2', 'admin/settings/2'),
          );
          $blocks['content'] = theme_item_list($items);
          return $blocks;
        case 1:
          $blocks['subject'] = l('admin/settings/2', t('Stage administratie 2'));
          $blocks['content'] = 'test 2';
          return $blocks;
      }
   }
}

If you refer to the documentation of hook_block, you can declare several block inside one hook.

The $delta argument is here to help you differenciate which block your are rendering.

About your links in the title, just use the l() function when you are setting the $block['subject'] value.

Example:

function planning_block($op='list', $delta=0, $edit=array()) {
  switch ($op) {
    case 'list':
      $blocks[0]['info'] = t('Stage administration block 1');
      $blocks[1]['info'] = t('Stage administration block 2');
      return $blocks;
    case 'view':
      switch ($delta) {
        case 0:
          $blocks['subject'] = t('Stage administratie');
          $items = array(
            l('Item 1', 'admin/settings/1'),
            l('Item 2', 'admin/settings/2'),
          );
          $blocks['content'] = theme_item_list($items);
          return $blocks;
        case 1:
          $blocks['subject'] = l('admin/settings/2', t('Stage administratie 2'));
          $blocks['content'] = 'test 2';
          return $blocks;
      }
   }
}
记忆消瘦 2024-10-28 16:57:30

您可以创建多个块,如 Artusamak 的答案所示,或者如果您希望将更多内容添加到单个块中,也可以简单地将更多内容添加到 $blocks['content'] 中。

$blocks['content'] = l('admin/settings/1', 'test 1') . ' ' . l('admin/settings/2', 'test 2');

请注意,如果您只需要固定链接的列表,可以通过创建菜单并向其添加链接来实现。每个菜单都会自动显示为一个块。无需自定义代码。

You can either create multiple blocks as shown in Artusamak's answer, or you can simply add more content to $blocks['content'] if you want it in a single block.

$blocks['content'] = l('admin/settings/1', 'test 1') . ' ' . l('admin/settings/2', 'test 2');

Note, if you just want a list of fixed links, you can do that by creating a menu and adding links to it. Every menu is automatically exposed as a block. No custom code required.

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