开发者

Fundamental understanding of how Views and Pathauto work together

开发者 https://www.devze.com 2022-12-31 22:20 出处:网络
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 a开发者_如何学JAVAm using blocks to display ce

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 a开发者_如何学JAVAm 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.


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!


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*).


In general is a good practice to theme the node page and do not let views generate additional urls. It can lead to several problems, as many modules link to the standard node page. Use views to generate listings that links to the node page.

You can also theme a node page without coding, using context or display suite modules.

Just let pathauto do the work, a good idea is to generate the alias based on the menu hierarchy, to have a consistent url scheme. Check out this question: Drupal 7:Pathauto patterns from menu structure hierarchy

0

精彩评论

暂无评论...
验证码 换一张
取 消