Drupal 中表的节点引用

发布于 2024-09-13 05:01:51 字数 315 浏览 3 评论 0原文

我有 Drupal 和 CCK,
我有一个名为文章的内容类型。
本文有 5 个节点参考。
我正在使用 CCK 中的表字段,并尝试将其连接到
参考文献,因此每篇文章[包含一个表字段]
将有一个包含 5 列的表格,每个产品一列
以及可以根据用户想要的内容更改的内容

但是我不太确定该怎么做,我尝试过
在参考中选择产品后将其添加到列中
通过jquery,它看起来很慢..有没有以前的解决方案?

图像要清晰 替代文本

I have Drupal with CCK,
I have a content type named Article.
This Article has 5 Node references.
I'm using the table field in CCK and I'm trying to connect it to
the references, so each article [that holds a table field]
would have a table with 5 columns, one for each product
and content that can change according to what the user wants

However I'm not really sure how to do so, I tried
adding the products to the columns once they are chosen in the reference
via jquery, it seemed sluggish.. is there any former solution to this?

Image to clearify
alt text

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

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

发布评论

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

评论(1

蓝眸 2024-09-20 05:01:51

您可以使用 View 来完成此操作,但在我们开始之前,最好先创建一个对您的节点进行一些更改。

  1. 不要为每个产品使用 5 个单独的节点引用字段,而是添加一个引用产品的节点引用字段。在字段配置中(位于内容类型的“管理字段”选项卡上),将“值的数量”设置为“5”。全局设置。

  2. 然后,删除 tableview CCK 字段。您不需要它,因为您要创建的视图将执行您想要执行的操作。

  3. 现在,转到网站建设 -> 浏览 --> 添加。输入视图的名称;假设列出。您可以将描述标签更改为您想要的任何内容,但将视图类型设置为节点。< /p>

  4. 现在,设置视图。在字段下,添加您想要在产品表中显示的字段;假设节点:标题节点:正文

  5. 过滤器下,添加节点:类型过滤器,以便视图仅显示产品,而不显示其他类型的节点。

  6. 基本设置下,将样式无格式更改为表格

    您现在将拥有一个视图,该视图将显示表格中的所有可用产品。下一阶段是限制该表仅显示特定节点引用的产品。为此,您将创建一个参数。

  7. 参数下,添加节点:ID。现在,视图将仅显示 ID 与传递给视图的参数匹配的节点。

  8. 选中每个参数允许多个术语,这样您就可以一次查找多个节点。

  9. 由于您不会手动传递这些参数,因此视图将自动生成其查找的参数。在参数不存在时采取的操作下选择提供默认参数

有几个可用选项,但没有一个与您想要的选项匹配:即所引用节点的节点 ID。因此,选择PHP 代码,以便您可以提供自定义参数。使用以下代码:

$arguments = array();
$node = node_load(arg(1));

if ($node->field_product) {
  foreach ($node->field_product as $product) {
    if ($product['nid']) $arguments[] = $product['nid'];
  }
}

return implode(',', $arguments);

这将查找页面的节点 ID (arg(1)),检查它是否具有产品节点引用字段 ($node->field_product,将 field_product 更改为字段的短名称),然后构建一个包含所引用的每个节点的 ID 的参数。它以 Views 期望的格式返回参数列表:1,2,3

现在视图已完成:唯一剩下要做的就是使视图显示在页面上。您可以创建一个显示,然后将该块添加到网站建设下的区域 -> 阻止。如果您转到引用产品的页面,该块将与引用块表一起出现。

如果您希望视图成为节点本身的一部分,请查看 View Reference 模块,该模块创建引用视图的 CCK 字段,就像节点引用引用节点一样。

You can do this with a View, but before we get to that, it's probably better if you make a few changes to your node.

  1. Instead of using 5 separate node reference fields for each product, add one node reference field that references products. In the configuration for the field (found on the Manage fields tab for the content type) , set Number of values to 5 under Global settings.

  2. Then, get rid of the tableview CCK field. You won't need it as the view you're going to create will do what you're looking to do.

  3. Now, go to Site Building -> Views --> Add. Enter in a name for the view; let's say listing. You can change the Description and Tags to whatever you want, but leave the View type set to Node.

  4. Now, set up the view. Under Fields, add the fields you want to show up in your product table; let's say the Node: Title and the Node: Body.

  5. Under Filters, add a filter for Node: Type so the view will only show products and not other types of nodes.

  6. Under Basic Settings, change the Style from Unformatted to Table.

    You'll now have a view that'll display every product available in a table. The next stage of this is to limit that table to only display products that a particular node references. To do that, you'll create an argument.

  7. Under Arguments, add Node: ID. The view will now display only nodes with IDs that match the argument passed to the view.

  8. Check Allow multiple terms per argument, which will let you look up more than one node at a time.

  9. Since you won't be passing those arguments manually, you'll have the view automatically generate the arguments its looking for. Select Provide default argument under Action to take if argument is not present.

There are a few options available, but none match the one you want: that is, the node IDs for the nodes referenced. So, choose PHP Code so you can supply a custom argument. Use the following code:

$arguments = array();
$node = node_load(arg(1));

if ($node->field_product) {
  foreach ($node->field_product as $product) {
    if ($product['nid']) $arguments[] = $product['nid'];
  }
}

return implode(',', $arguments);

This will look for the page's node ID (arg(1)), check to see if it has the product node reference field ($node->field_product, change field_product to the short name of your field), then build an argument containing the ID of each node referenced. It returns the argument list in the format that Views expects: 1,2,3.

Now the view is complete: the only thing left to do is make the view appear on the page. You can create a Block display, then add that block to a region under Site building -> Blocks. If you go to a page that references products, the block will appear with the table of referenced blocks.

If you want the view to be a part of the node itself, look into the View Reference module, which creates a CCK field that references a view much like Node Reference references a node.

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