Question

I have a content type with around 50 fields with three groups A,B and C(grouped in views). I have a view which shows the new content added in table format(limited fields). I do not want the table to be huge so I have created another view - page containing 3 blocks( A- 10 fields, B- 20, C-20) which shows the content according to the group(A,B,C).table view Now the analysis result link has to redirect to the second view and show the correct content corresponding to the content added( nid to be the same), but all the links in every row of the table show the same result- the recent most view result. The link to content redirects correctly to the content but I want it to redirect it to the correct view result. I have to have a unique url for ever anaylsis result link. I prefer doing it the drupal way, so I tried adding relationship-to show results where nid is same, but it required an absolute value(like nid=5). I tried making the page path /{{nid}} too but it did not work. Please help me with the solution.

I followed the solution postyed by prkos. Here is the current progress:

View1

View2 View 2 contextual filter

result/64 page not found

Was it helpful?

Solution

Construct link in the first Views

You need to create the correct link in your first Views yourself.

You will need the ID field for that purpose since that is the information you need for filtering the second Views.

You don't want the ID show in that Field, we need to construct the link that has the ID in it so that it can be passed to the second View as an argument.

When you add the ID Field set its Formatter to Unformatted just to make sure you get plain number out of it.

Under Rewrite results select Override the output of this field with custom text and in the Text area enter the text you want as your link text, something like "More info about this/Analysis", otherwise the text will be the content ID number.

Again under Rewrite results select Output this field as a custom link and put the path of your second Views path with the token for your ID field. It will look something like this:

/my-second-views-path/{{ nid }}

You can check what your token is in the Replacement patterns a bit further down the page. You can also use the raw value token.

You can check your configuration is correct by hovering over the text (it should be a link) and seeing in the browser tooltip (usually bottom left of browser viewport) that the link has been constructed correctly.

Add Contextual ID in the second Views

To make the second Views show only the one correct result when you click on the constructed link in a particular row in the first View you need to make it aware of that number in the link.

This is done by adding a Contextual ID filter in your second View. Contextual filters are under Advanced options, usually on the right in Views configuration.

Configure it with these settings:
When the filter value is NOT available
Provide default value
Content ID from URL
When the filter value IS in the URL or a default is provided
Specify validation criteria
Validator: Content
Content type [yourCT]
Set other options to what makes sense in your case.

You can test that the configuration is correct by entering a known content ID number into Views Preview field, it should show only the row with the content with that ID.

The Path of the second View should be /my-second-views-path/%. The % character there represents the input for the first Contextual filter (the only one in this particular case).


Final test is to visit the First View page and click on a link, it should take you to the second Views page and only show one result, the one with the corresponding ID number.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top