Shelter 100 Fallout Shelter Achievement Guide Fallout I have some block views in my sidebar that show events marked as a highlight happening in certain cities. Nodes are organized into cities using taxonomy.

When I load a node directly I have an URL like www.host.com/events/new-york/name-of-my-nice-event

I have some other page views that show teasers for all events in a certain city: www.host.com/events/new-york

Also I have some static pages that are valid for all cities, e.g. www.host.com/about-us

The sidebar blocks showing the highlights are available throughout the whole website. Now I want to make sure that the blocks in my sidebar only show those nodes for the selected city based on the taxonomy provided in the URL. (except for the static pages as there is no taxonomy in the URL, but those are not that important)

So far I tried to pass my view the taxonomy term as an argument using PHP as standard argument:

if Fallout Guide Shelter Fallout Achievement Shelter 100 (arg(1)) { $term = arg(1); return $term; }

This works fine on the above mentioned page views (e.g. www.host.com/events/new-york). But when I load a node directly www.host.com/events/new-york/name-of-my-nice-event my block only shows the empty text.

I thought that arguments are indexed like this:

 events/new-york/name-of-my-nice-event ^0 ^1 ^2

So I don't understand why arg(1) does not return new-york when I am viewing the node detail.

First of all, with path and path auto what you see is not always what you get.

Fx I could setup pathauto for my articles nodes to generate urls like this


So if I wanted the title I should use arg(2) right?

No! (arg(2) is actually NULL in this case.)

The reason is that the url that's generated by path auto is a fake url, that gets translated into a Drupal url. In the case above what I get is node/[nid]. So eventhough the node title i in the url, I can't get it by using arg(), but I can get the nid by using arg(1)

I can't guess what your urls map to, it depends how you have set up your site what modules you use etc.

A good advice if you do a lot of these context aware things, is to look into panels. It's made to be able to tell modules like views about the context which it is present. Like fx terms, nodes, etc, and you could use this to pass arguments into views.

100 Shelter Fallout Shelter Fallout Achievement Guide Panels can do a lot more and is quite complex, but if you need to do a lot of this stuff, it is probably worth the investment.

  • Thanks a lot for pointing me in the right direction. After some time of trying I managed to solve my problem with the posted solution. –  maze Nov 3 '10 at 17:52

Solution to my problem:

if (arg(0) == 'node' && is_numeric(Shelter Shelter Achievement Guide 100 Fallout Fallout arg(1))) { $node = node_load(arg(1)); if (count($node->taxonomy) > 0) { foreach ($node->taxonomy as $term) { $term = $term->name; } } $term = strtolower($term); // for some reason needed in my case } else { $term = arg(1); $term = str_replace(Achievement Shelter 100 Fallout Shelter Guide Fallout '-', ' ', $term); // for some reason needed in my case } return $term;
I Crash Do Application My From How Overflow Stack data Obtain Android qTSnwwOH

While this was technically possible with Views 2 as described in some of the other answers, Views 3 has this integration built in.

You can create an argument for the taxonomy term id and then choose "Provide default argument". This will then give you an option for "Taxonomy Term ID from URL" and "Load default argument from node page..."

This will allow you to take the taxonomy of a page and pass that as an argument to your view block.

Note: Views 3 is currently in Alpha 3 but in my experience is at a relatively stable state and I am using it on production sites. If it has features like the one above that you find useful please use it, test it and submit bugs/patches if you encounter any issues!

Guide Fallout Fallout Shelter Shelter Achievement 100 Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.Fallout Shelter Guide Shelter Fallout Achievement 100

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