Creating Tabbed Pages With Simplicity Using Views

GreenLED - March 7, 2008 - 17:19

I am hoping that someone will look at this post. Recently many of my posts have just sat unanswered. Surely you've experienced this fate :).

Here's the problem. I have created a view like thus...

( page )
Provide Page View: Yes
URL: node/$arg/tab2
View Type: Table View

( menu )
Provide Menu: Yes
Provide Menu as Tab: Yes
Tab Weight: 2
Menu Title: Author

Assuming ONLY the above settings, you'll end up with a node looking like this...

Some Node Title
_| View | Edit | Author |_

Now, here's what I'm trying to accomplish... In that "Author" tab I want to somehow filter out all nodes and widdle it down to locate the authors profile or "bio" page. Here's how I'm doing this. I've created a content type called "Profile" I've limited the creation of the Profile type to "1" per user by using the node family module oddly enough. So -- I need to somehow tell views to find me 1) the author of this particular post ... then 2) to filter down to that authors profile. Since they only will have one -- it will only report back with one node -- thier profile. How can I do this?

A views expert should tackle this one. I need help on views, I like it a lot, but it still has some limitations.

Three steps

nevets - March 7, 2008 - 18:49

You need to add three things to your view.

Under 'Arguments' add 'User: UID is Author' as an argument. Set 'Default' as desired, I like to pick 'Use Empty Text' as it makes it easy to provide default text if the view is empty.

Still under 'Arguments', under 'Argument Handling Code' in the 'Argument Code' textarea add

$args = array();
// Set first view argument to user id of node be viewed
if ( is_numeric(arg(1)) ) {
  $node = node_load(arg(1));
  $args[0] = $node->uid;
}
return $args;

And as the last step under Filters add a filter for 'Node: Type' and select the approriate value for type.

Wow! Genius! I really don't

GreenLED - June 25, 2008 - 17:11

Wow! Genius! I really don't know how to thank you for that. That's a break-through for me. Thanks a lot. Now to understand exactly what's happening. I'd like to understand the logic a little bit because that will be the a real mental conquering of this views module. So, let me try to logic this out...

The Argument: User: UID is author
I don't understand what's going on here. Here's what I'm expecting is going on... So, we're at node 35 let's say -- so the url in the browser would be...

node/35/author

my argument is "35" -- right?

Therefore -- what's is exactly happening here. *light on*

Ok, I think I'm getting this so what this argument is saying is...

If this node (obviously testing all nodes) is by this user-id, show it to me.

However... why in the world are you setting the argument to "1"? That does not make sense. I'm not the only one who's going to be authoring posts. It sounds like what you did was set the argument to 1 assuming I'm the only author. I don't understand this part. Explain it to me please.

Thank you so much for enlightening me on this. I'm trying to really grasp views, it has some incredible potential if used correctly. Thanks agian.

» Respectfully, GreenLED
» Stable Files . net

In fact -- now that I think

GreenLED - March 7, 2008 - 20:39

In fact -- now that I think about it, the argument handling code should say "set argument 1 to the id of the author of the post (submitted section)" I'm confused why you had it set to 1 only.

Opps, I forgot to change the comment

nevets - March 7, 2008 - 21:00

I fixed the comment so hope that helps.

In general, the first views uses the path arguments but by adding the PHP code we are setting them based on the path arguments. In this case we expect the 2nd path argument { arg(1) } to be the nid of the node being viewed. From that we get a node and set the first views arguments { $args[0] } to be the user id ($node->uid) of the node being viewed. This then limits any nodes returned by the view to be ones owned by the same user. The filter then limits the nodes so they are only of the type you are using for the profile. Since there is only one of those the view should return 1 node of that type owned by the same person who created the node being viewed.

Understood. Let me take this

GreenLED - March 8, 2008 - 14:17

Understood. Let me take this oppertunity to ask another question along the same lines right here since I have your attention. I have had the most difficult time trying to get answers -- and I'm sure there are some others that will benefit from this question and it's answer...

Taking the same type of example above -- let's assume we create a view called "event_overview"

Let me lay out the options like before so there is no confusion...

(page)
Provide Page View: Yes
uRL: event/$arg/overview
View Type: List View
Title: %1

(menu)
Provide Menu: Yes
Provide Menu as Tab: Yes
Menu Title: Overview

(fields)
Text: Overview (field_overview)

(arguments)
Node: ID

(filters)
Node: Published ... Equals ... Yes
Node: Type ... Is One Of ... event

Let me explain the idea here.

The basic idea is to have ONE node, in which you have MULTIPLE fields (cck fields). What these views are accomplishing is -- they are pulling different fields from the same node, thereby creating a very nice navigation inside of one node. Examine the following urls...

event/$arg/overview
event/$arg/schedule
event/$arg/registration

Therefore... event/1/overview would have the fields...

(fields)
Text; Overview (field_overview)

Keep in mind we have "List View" enabled.

And thus we would see event 1's overview text. You follow?

Now when we "tab over" to event 1's schedule for instance we will have the field...

(fields)
Text: Schedule (field_schedule)

Am I making sense? Good...

So, here's the problem...

All of the above works perfectly for me. I am able to create tabbed pages like this, and am able to manually (note) type in for example 'example.com/event/1/overview' -- BUT this is a problem because I do not know of a way to create a view that will display a listing of these "Events" -- why not??? -- because when i create a listing it will create a listing of nodes -- not views -- so thus...

I would get a listing of events like this...

(assuming list view)
Event 1 title...
Event 2 title...
Event 3 title...

When you would click one of these it would lead to a NODE not a view... thus my whole cool tabbed view means nothing then -- because the links on those titles are to nodes. How can i create a listing that will display events that will for example lead to the "event/$arg/overview" page when you click a listed event?

Do you know what I mean?

Answer depends on view type

nevets - March 8, 2008 - 14:56

Answer depends on view type for list of events, but basically you will need to do a little theming. In the case of a list of Teaser or Full Nodes you would want to copy node.tpl.php to node-event.tpl.php and edit node-event.tpl.php and change the way the title is linked. For a list or table view you will need to override the theme function for the view and link the title yourself.

Node Template...

GreenLED - March 8, 2008 - 17:34

I think I see the light now. I've underlined the portion I'm almost 100% I would need to change. So, I would take this url and insert the node id into the url... Well let me give it a try -- see if you agree... But, I understand exactly what you're saying has to happen.

<DIV CLASS="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
    <?PHP if ($picture) {
      PRINT $picture;
    }?>

THIS LINE:
<?PHP if ($page == 0) { ?>
<H2 CLASS="title"><A HREF="<?PHP print $node_url?>">

What would I use? Something like ...

<PHP PRINT "event/" . $node->uid . "/overview"; ?>

That is correct

nevets - March 8, 2008 - 18:25

That is correct if you are replacing <?PHP print $node_url?> with <?PHP PRINT "event/" . $node->uid . "/overview"; ?>

Actually, that's wrong. I

GreenLED - March 8, 2008 - 19:09

Actually, that's wrong. I just noticed -- it should be...

<?PHP PRINT "event/" . $node->nid . "/overview"; ?>

I'm looking for the "nid" instead of the "uid" of the post.

In any event ... one more issue... This aparently is NOT working in table view. How can i customize the "Node: Title" in table view. For some reason I don't think that the "teaser" title is the title that is displayed (at least as far as the link goes) in table view.

In other words... I did customize it in my template, but it did not work in table view. It just pulled up the node. Any ideas?

Need to theme the view

nevets - March 8, 2008 - 19:18

Need to theme the view, both table and list views do not use the tpl.php for the nodes content since they are showing fields and not the whole node. See "Theming you views" in the handbook for more details.

Problem...

GreenLED - March 8, 2008 - 20:29

That won't work. The theming apparently only works with lists with PHP-Template. Do you know of any other way to do this -- it sounds like this would be the only option. It sounds like this isn't going to work anytime soon.

You are not using a phptemplate based theme?

nevets - March 8, 2008 - 20:33

You are not using a phptemplate based theme?

I am -- did not say that

GreenLED - June 25, 2008 - 17:11

I am -- did not say that correctly, it ONLY works with phpTemplate LISTS, not tables apparently, which is what I want to do.

How would you go about this? Do you have a test site you could give it a try on? I'm really not well-versed in theming views at all.

» Respectfully, GreenLED
» Stable Files . net

You know what would solve my

GreenLED - March 8, 2008 - 22:02

You know what would solve my problem in a much easier way?

If I could rename the path of "node/" by content type -- then I could add the tabs I wanted to those types and then I could build my lists of events without having to worry about my tabs affecting all my other content types. In other words...

Instead of having "node/#" for say an "event" content type,

I could hve "event/#"

This would NOT apply to everything. ONLY to event types.

This would be perfect because I could then simply apply my tabs to "event/$arg/tab" and then when I build my lists of events clicking on them to view would not be a problem. Isn't there an answer to this? I DO NOT think that Path can do this by the way -- just as a heads up. I'm pretty sure Path only allows you to change the alias of an ALREADY existing path. Therefore -- if I changed node/ to event/ that would change my whole site that way -- and I only want to change node/ to event/ for the event content type... Do you know what I mean?

Maybe yes, Maybe no

nevets - March 8, 2008 - 22:36

Pathauto might be able to handle the path aliasing but I am assuming the paths to the views module need to be actual paths (and not aliases), could be wrong though as I have never tried that.

I hate to say it, but

GreenLED - June 25, 2008 - 17:11

I hate to say it, but Pathauto is not the answer. My feeling is that Pathauto's functionality realy could not hold up to what I'm asking it to do. See, how would it be able to have "event/" co-existing with say "file/" It just will not work. I have to find a solution that is in views. I'm convinced of this because the scope of what I'm trying to accomplish can't just be put together with hacks. You know what I mean? Whatever the solution is -- it has to be somewhere in a core module or some other module -- I think the path or path-auto module would be on the verge of a jerry-rig or some such thing. My hope is that I can find the answer within views or something that I don't have to install. I'm very un-easy about how much overhead all of these modules present into my website -- but that's what you get when you're trying to make things easy -- you end up gathering up overhead. Although -- I really shouldn't complain -- it's nice to be able to have all of this usability without having to program -- much anyways. Drupal really I think is more of a learning tool more than anything -- it forces you to logically break down what you're doing. Anyhow -- what are your thoughts on this?

» Respectfully, GreenLED
» Stable Files . net

A few months down the track

andrewsuth - March 6, 2009 - 23:17

A few months down the track now...

I'm very interested in knowing if you came up with an easily workable solution to this issue?

Andrew

 
 

Drupal is a registered trademark of Dries Buytaert.