CCK 字段和视图之间的链接

发布于 2024-08-25 03:39:32 字数 94 浏览 6 评论 0原文

我想使用视图来选择内容类型字段中的节点。该视图必须接收一个作为内容类型的另一个字段的参数。 有人可以解释一下如何将参数从现场传递到视图吗?

原谅我糟糕的英语

I want to use a view to select nodes in a content type field. This view must receive an argument that is another field of the content type.
Can someone explain me how to pass the argument from the field to the view?

Excuse my poor english

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

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

发布评论

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

评论(3

谁人与我共长歌 2024-09-01 03:39:32

您也许可以使用视图参数附加模块。它将允许视图的参数来自 cck 字段。有关此模块的更多详细信息(来自其项目页面):

此模块包含一组添加以下选项的视图处理程序和插件:

  • 参数默认当前节点CCK

    允许将当前节点的 cck 字段值作为默认参数加载

  • 参数默认请求参数

    允许将 get 和 post 参数作为默认值

  • 参数顺序排序

    排序处理程序,允许项目的顺序基于其在多值参数中的顺序

You might be able to use the Views Arguments Extras module. It will allow the argument of the view to come from a cck field. Some more details about this module (from its project page):

This module contains a group of view handlers and plugins that add the following options:

  • Argument Default Current Node CCK

    allows for cck field values of the current node to be loaded as default arguments

  • Argument Default Request Params

    allows for get and post params as default values

  • Argument Order Sort

    a sort handler, that allows for the order of items to be based on their order in a multi-value argument

自由范儿 2024-09-01 03:39:32

我相信您可以使用参数验证来验证参数,此时您可以在 $handler->argument 值传递到视图之前自由更改它。

I believe you can use the argument validation to validate the argument, and at that point you are free to change the $handler->argument value before it is passed in to Views.

情定在深秋 2024-09-01 03:39:32

如果您只想根据 CCK 字段的值更改视图显示的内容,我发现的最简单的方法是使用 views_embed_view() 将视图嵌入到模板中。我认为模板文件中类似的东西会起作用:

//Use the dsm function to print out your $node object
//to get the name of the field you want to pass as an arg
//like this: dsm($node); 
//Assuming that the value of that field is in $node->cck_field['0']:
print views_embed_view('name_of_view', 'name_of_display', $node->cck_field['0'];

views_embed_view() 只需要第一个参数(视图的名称)即可工作。它将返回指定视图的默认显示的 HTML。我们将特定的显示作为第二个参数传递给它。第二个参数之后的任何内容都会作为参数传递到视图中,因此我们将字段的值作为参数传递给视图。请参阅链接,获取有关该函数如何工作的一些文档。

If you just want to change what the view displays based on the value of a CCK field, the easiest way I have found is to embed a view into the template using views_embed_view(). Something like this in your template file would work I think:

//Use the dsm function to print out your $node object
//to get the name of the field you want to pass as an arg
//like this: dsm($node); 
//Assuming that the value of that field is in $node->cck_field['0']:
print views_embed_view('name_of_view', 'name_of_display', $node->cck_field['0'];

views_embed_view() only needs the first argument, the name of the view, to work. It will return the HTML for the default display of the named view. We pass it a specific display as a second argument. Anything after the second argument gets passed into the view as an argument, so we pass in the value of the field as an argument to the view. See this link for some documentation on how the function works.

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