Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fundamental understanding of how Views and Pathauto work together

I am having fundamental problems understanding when to use a pathauto rule, and when to use a views page path. I have several custom content types, and I am using blocks to display certain parts of nodes on certain paths. Then I use a views page to display the main node on a path.

When I do this, I can't use pathauto, as it overrides the paths I set in views. Eg.. If I set up a views page path of "location/%", and set a pathauto rule for Location content types of "location/[title-raw]", when I browse to mysite.com/location/mylocation pathauto wins, and simply displays the full node. And if I can't use pathauto, I can't add arguments on my blocks, because Drupal doesn't understand what it's looking at anymore! Arrrg!

I've tried installing Util, and altering the weight of the modules, but that didn't work. But I shouldn't have to do anything crazy like alter module weights, right? There must be some basic flaw in my thinking.

How do you keep your paths and content organized?

Help me flow like water, help me become the cup.

like image 908
Dan Johnston Avatar asked May 26 '10 14:05

Dan Johnston


2 Answers

Ok, I've solved my problem. The actual question I should have asked was:

How do you display a single node?

I was basically using Views to style a single node. Of course, this is not what Views is designed for. See others with similar problems:
http://drupal.org/node/400400
http://drupal.org/node/316907

My solution:

  • Let pathauto do all the work.
  • Add, arrange and style your content as desired at the theme layer.

In more words: remove views page view, taking the corresponding location/% path with it. Set up your pathauto rules the way you want. Copy node.tpl.php to your theme directory. Duplicate that file and rename it node-[type].tpl.php. Alter node-[type].tpl.php instead of setting up rules in Views.

For more help theming a specific CCK content type see:
http://drupal.org/node/266817

Don't forget! When using phptemplate node-[type].tpl.php suggestions, there must also be an original node.tpl.php template present in your theme directory or the template suggestion is ignored.

Hope that helps someone else!

like image 56
Dan Johnston Avatar answered Oct 24 '22 12:10

Dan Johnston


Right. The % is a views argument, views superceeds URL aliasing every time. Drupal expects anything after location/ to be the passed in value you are looking for which is why it doesn't understand, or you aren't getting the result you want.

Why are you using views though to control a node view? If you are adding blocks to a view, you should be able to assemble the data in views, and use the Block admin to set the path it displays on (location*).

like image 3
Kevin Avatar answered Oct 24 '22 10:10

Kevin