views:

32

answers:

2

I'm having some problems creating a view for a node within my website.

The content has a path of 'content/%' where % is the title of the node. What I tried to do is to create a page view in the Views2 module, but to no avail. When I attempt to preview with the name of one of my nodes, nothing appears, and when I visit the node live, it renders text to the screen without any formatting.

Here are some of the settings from my View...please let me know if I should provide any extra information!

Page Settings

Path: content/%

Arguments

Node:Title

  • Title: %1
  • Action to take if argument is not present: Provide default argument
  • Default argument type: Node ID from URL

Edit

I will describe the behavior I'm expecting to see...

I have a list of nodes in my website in a view....that shows up without any issue.
What I would like to do is click on the node and go to that node's page, which is basically an expanded view of a single item from my list.

I thought what I could do is clone my list view and then add an argument to trim the scope from a list to a single item, but this isn't working too well. What is the proper method for styling a single node?

+1  A: 

Edit: Based on your edit, you've already used Views to create a list of nodes, and now you want to be able to click on one and get to the node page.

If you just want the default node output, you shouldn't have to do anything else. Don't try to use a View to override default node rendering; Drupal will print it out by default.

If you want to theme your node uniquely (beyond what moving the fields around and changing display settings in the UI allows you to do), then you should look at custom template files and theming. Resource here: http://drupal.org/theme-guide

You can change the default node.tpl.php file if you want to change how all nodes are displayed, or you can copy that file and rename it to node-name_of_custom_type.tpl.php to uniquely theme a custom content type you've created, but I'd suggest reading up on the Drupal theme system before making those changes.

End of edit


When you want to assign a path to a Views Page display, you shouldn't model it after any existing paths (e.g. node paths, as you mention). It should be something unique to avoid path alias conflicts. So for example:

my-path/%

Now, if you're just looking to embed a view inside of your node (and you want to pass along the node id as the argument), you're half-way there. Your Arguments setting, based on your description, is correct. However, you don't need a page display.

Here are a couple of options:

  • Quick 'n' Dirty: Create a block display (which doesn't need a path) and stick the block in a region on the node page (I've used the content_bottom region) to "embed" it in your node
  • Powerful, Flexible: Use the views_embed_view function (api docs here) inside your node (the body or a CCK field, just make sure to use the "PHP filter" input format)

If you use views_embed_view, you have the flexibility of sticking your Views results wherever you like, and you don't even need to create a Views page or block display, because that function can just use the "Default" display.


Note: If you export your View and save the export code on a site like pastebin or drupalbin, folks here can import the View and see it directly to help answer your question in full detail.

semperos
thanks, i think going with your quick 'n' dirty suggestion will be easiest for me to get it up and running...in the future i may look to the embed_view if i need to do more, but for now this is ok :)
espais
+1  A: 

Okay, got it. :)

Using Node: Title as an argument is pretty tricky: with the default settings, the argument must match the title exactly. So, if you wanted to match on "Test value", your path would need to look like content/Test%20value (note the caps).

This will get you the node you want. You said you have default argument set to Node ID from URL; that really doesn't apply for Node: Title arguments. What it does is attempt to find a numeric Node ID and use that as the argument, which will never validate on a Node: Title unless the node's title happens to match the node's ID.

If you just want to display all the nodes if there isn't a title argument present, select Display all values as the action to take if an argument is not present. If you want to display all nodes if the title argument is invalid (like a typo or something), make sure Display all values is set in the Validator field group for the action to take if the argument does not validate.

Because of the exact match restriction on node titles, it's generally not a good idea to use Node: Title as the argument. Instead, consider using "content/NID", where NID is the Node ID of the row's node, as the link in the original view Then, instead of the Node: Title argument in your view, use the Node: ID argument. This should make it less error-prone.

Mark Trapp

related questions