The relationship between the CCK field and the view

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

Sorry my bad english

+4
source share
3 answers

You may be able to use the Module Module for Additional Arguments . This will allow the view argument to come from the cck field. More information about this module (from the project page):

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

  • Argument Default Node CCK

    allows loading cck field values โ€‹โ€‹of the current Node as default arguments

  • Default Argument Request Parameter

    allows you to receive and send parameters as default values

  • Argument Order Sort

    a sorting handler that allows you to sort items based on their order in a multi-valued argument

+2
source

I believe that you can use argument checking to verify the argument, and at this point you can change the value of the $ handler-> argument before it is passed to Views.

0
source

If you just want to change what the view displays based on the value of the CCK field, the easiest way I've found is to insert the view into the template using views_embed_view() . Something like this in your template file will 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 HTML to display the default named view by default. We give it a specific display as a second argument. Everything after the second argument is passed to the view as an argument, so we pass the value of the field as an argument to the view. See this link for some documentation on how this feature works.

0
source

Source: https://habr.com/ru/post/1304130/


All Articles