6

I have an issue and i'm hoping to get some advise.

I have a view created that show content based on the url:

eg:

domain.com/item/one

Shows fields for my node with the title one

domain.com/item/two

Shows fields for my node with the title two

etc etc.

The path for the PAGE in views is set to /item

What I'm having trouble with is I need to have a BLOCK (becuase I'm making it collapsable) show under that page with the specific URL show the body field for that node.

eg:

domain.com/item/three

Shows fields for my node with the title three as well as a block that show the body field for node three

I have set the Contextual filter for the PAGE to:

Content: Title

When the filter value is NOT in the URL
Show "Page not found" 

Exception value : Empty (All removed)

Under More:
Case : Lowercase
Case in path : Lowercase

Transform spaces to dashes in URL : Checked

This works for the page but please let me know if I have set this up incorrectly.

I have set the same Contextual filter for BLOCK and it works in views preview but not on the page with the URL:

domain.com/item/three

I also tried adding Global: Null Contextual filter before the Content: Title filter which allowed me to put item/three in the preview and it works (before worked with just three). This also didn't work on the actual page.

Any advise on this would be greatly appreciated.

1 Answer 1

15

Contextual filters works well for any display type that has a path. A path makes it easy for views to determine what information should be passed into the contextual filters.

The problem with blocks is that they don't have a path. Views does not look at the current url and automatically pass values to the filters because it has no idea which parts of the url to use.

You can get around this by using Default Values (or page manager/panels, but that's a whole other topic).

In the settings for your block contextual filter, you will want to override the configuration and select Provide a default value. Under type choose Raw value from URL and set the Path component to 2 (the path component will be different depending on your URL, but for domain.com/items/node-title the component is 2)

enter image description here

When you assign your block to a region, you probably want to set the allowed paths so this block won't show up anywhere else. The path component is "hard coded" so if your path ever changes you will need to adjust it.

2
  • 1
    You're likely better off using "Content ID from URL" as "raw value" allows partial matches. E.g. "blog/post-1" will display content from "blog/post-11".
    – ElbertF
    Jan 25, 2012 at 0:43
  • Thanks for this, and although I feel a little dirty using this method I have already spent too long trying to find a better one.
    – markd
    Aug 15, 2013 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.