I have setup a view to output a "video" node list in a "video collection" node. The "video collection" has a CCK nodereference field refer to the related "video"s. However, I can not output the title of the video with a corrected link by using "Output this field as a link"

The views has the following setting:
@ filter: video content type

@ argument 1: Search: Links from ; Action to take if argument is not present: Provide default argument --> Node ID from URL ....this will automatically pass nid of "video collection" as argurment

@ fields: --> Node: Title; Output this field as a link checked; Link path: node/%1/[nid] ....just follow the suggested replacement below, and this should output the field with link like node/{nid of video colleciton}/{nid of Video}

However, the real output of the above fields was node/{title of video colleciton}/{nid of Video}??? The %1 returns the title from URL instead of node ID.

Is this a bug? If not, how can I output %1 as node ID???

Thanks in advance.

CommentFileSizeAuthor
#3 Video Playlist 2.jpg139.41 KBhappydrupal
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

happydrupal’s picture

Version: 6.x-2.0-beta4 » 6.x-2.5
Priority: Normal » Critical

My bad...just correct to the right version.

merlinofchaos’s picture

Category: bug » support
Priority: Critical » Normal
Status: Active » Fixed

This is neither a bug, nor critical. %1 prints the title version of the argument, not the raw argument. It is possible that there needs to be a method of printing the raw argument.

In your case, you can add a node: nid field, set it to 'exclude' and move it ahead of the item you want; then use that for your token.

happydrupal’s picture

Status: Fixed » Active
FileSize
139.41 KB

@ merlinofchaos:

Thanks for the quick response. But I have to open again since your suggestion didn't work and I need support again.

This view was embedded in the "video collection" only. I did use your suggestion in Link path: node/%1/[nid] to bring out the "video" node ID as [nid] in the second argument output. But I can not use the same trick to bring out the "video collection" node ID since it was injected to the view by the following Argument setting.

Search: Links from ; Action to take if argument is not present: Provide default argument --> Node ID from URL

I think I still need a way to printing the raw argument instead of the title version of the argument.

Attached please also find my whole idea for the view since I can find any module for this. The view we discussed here was in the lower block. The other view in the upper block uses the second argument of the output link from the the view we discussed here to display the selected video. This also related my other feature request of Panel in #471228: Is that possible to make $links from a node as a different content when doing node override???.

It's still amazing though I can use View to do such a thing. So close............................

Thanks in advance.

happydrupal’s picture

Category: support » feature

@ merlinofchaos:

I still can not figure out how to solve my problem since %1 prints the title version of the argument, not the raw argument.

Is it possible that there needs to be a method of printing the raw argument in the near future???

Thanks in advance!

agentrickard’s picture

Right now, you need a custom argument handler, since the node handler does this translation for you.

Instead of using the argument in your view, can you instead load a hidden field and use that token instead?

Long term, here is a possible solution, which requires code.

1) Remove the custom title_query() options from the provided argument handlers.

2) Allow views_handler_argument to set the argument value based on a field replacement trick:

-- Read hook_views_data() for this argument to determine what fields can be referenced from this argument.
-- Provide a select list for choosing the field to load when using this argument.
-- Allow handlers to set default values for this selection (so NID would use node.title).
-- On title(), run a lookup query to replace the raw argument with the data from the desired field.

3) Profit!

Alternately, we could just specify a 'raw' checkbox to disable title_query().

kenorb’s picture

happydrupal’s picture

@agentrickard

Thanks for your response, even I can not fully understand nor help in the long term solution you suggested.

However, My view was embedded in the "video collection" only as mentioned above. I did use your suggestion in Link path: node/%1/[nid] to bring out the "video" node ID as [nid] in the second argument output. But I can not put any hidden field to bring out the "video collection" node ID since it was injected to the view by the following Argument setting.
Search: Links from ; Action to take if argument is not present: Provide default argument --> Node ID from URL

Will you kindly show me how to do that? Thanks in advance.

happydrupal’s picture

@kenorb

Thanks, I'll checking it.

happydrupal’s picture

@kenorb

I just follow your suggestion and create the TPL file of views-view-field--my_view_name--field-image-fid.tpl.php since I just want to replace the %1 from the title version of the argument to the raw argument.
That is
Find title version of the argument --> $node->title
Replace with the raw argument --> arg(1)

The code in views-view-field--my_view_name--field-image-fid.tpl.php is listed below

<?php
$output = str_replace($node->title, arg(1), $output);
print $output;
?>

However, $node->title return 'null' so nothing really changed. What is the correct variable to use which return the node title of the node?

Thanks in advance.

happydrupal’s picture

More search then found a modification can do the trick.

Link path: node/%1/[nid] ..............remains

with a views-view-field--my_view_name--field.tpl.php in the theme folder ..... though it's trick to find the right tpl name to use

code inside the views-view-field--my_view_name--field.tpl.php

<?php
$node = node_load(array('nid' => arg(1)));
$output = str_replace('/'.$node->title.'/', '/'.arg(1).'/', $output);
print $output;
?>

The above code will swap the %1 from the title version of the argument into the raw argument.

Thanks for all of you who pass the assistance.

kenorb’s picture

happydrupal:
If I understand correctly by using Views argument you will have title of the node as default.
See: http://drupal.org/node/483036#comment-1682060 #5 and #6
So in your case you don't need this tpl file.

happydrupal’s picture

@kenorb

Gee..............I just figured out part the myth behind #5 and #6. :p Indeed, a simple solution is always the best solution. Thanks for reminding.

However, I still can not figure out how to load the parent id as a field as #6 mentioned??? And I had been suffered from this for these weeks. Any suggestion or help?? Thanks in advance.

BTW, in my case I had to put the nodereference field in the Parent node and used "Search: Links from" as the first Argument to find the child nodes in view. I think that's why I can not find the way to put nid of parent node for the hidden field.

happydrupal’s picture

@kenorb

Finally, I still take your method in http://drupal.org/node/483036#comment-1682916.

%1 will not only display the title version, once there's any Reserved Characters in HTML in the title it could be worse. It will return Penny%26%23039;s Show for "Penny's Show".

That is:

Link path: node/[arg1]/[nid] ..............replace %1 with [arg1]

with a views-view-field--my_view_name--field.tpl.php in the theme folder with code below to replace [arg1] into arg(1)

<?php
$output = str_replace('%5Barg1%5D', arg(1), $output);
print $output;
?>

Thanks anyway.

disandov’s picture

Hi everyone,

I've tried the soultions posted above but I cannot get them to work.
I'm a newbie, and been looking around for a solution to this issue for a long time.
I would really appreciate if someone cand help me with this.

thanks a lot.

happydrupal’s picture

@ disandov

Could you provide a more specific scenario?

The appropriate name of tpl.php should be the trickiest part IMHO.

disandov’s picture

I have a block view called "top_video_block", which uses a node reference argument to show content related to the current node. Let's say i'm in node/38, then, the block shows the content wich references to that node.

I've created another view called "videos_page", which is meant to show the rest of the content which is not shown in the block. The path to this view is "node/%/videos_page"

In the block view, i added a field with the link: "node/%1/videos_page", where %1 is argument 1, which should give me te node id, but the output gives the following: "node/The%20Kooks%20en%20Chile/videos_page/". So views is using the title instead of the nid.

I made a tpl called views-view-field--top_video_block--field.tpl.php and inside wrote this code:

<?php
$node = node_load(array('nid' => arg(1)));
$output = str_replace('/'.$node->title.'/', '/'.arg(1).'/', $output);
print $output;
?>

but it is still not working...
I'm kind of lost at this point and don't know what to do.

I would really appreciate your help.

Thanks,
D.

happydrupal’s picture

disandov’s picture

@happydrupal

thanks for your help
I think you were right... I think i'm not using the right tpl.php name
My view is named top_video_block

i tried using the name: "views-view-field--top_video_block--field.tpl.php" but it didn't work.
i'm putting the link in a field called Global: Custom Text
could you give me a hint on how to write the tpl.php name correctly?

thanks.
D.-

happydrupal’s picture

@disandov

Try "views-view-field--top-video-block--field.tpl.php". Hope this helps..............

disandov’s picture

@happydrupal

Still having no success...
I even cloned the view and named it "topvideoblock" in order to discard any possible confusion with "-" or "_"
Shouldn't this issue be common? Maybe there's another way to do what I want.....

happydrupal’s picture

@disandov

Yeap, Help text in Views mentioned that The active template for each plugin -- which is the most specific template found on the system -- is highlighted in bold. As far as I know, the theming information in Views will not map your tpl.php in BOLD sometimes. But it really works!!!

======================================================

updated on 6/27

Make sure you didn't use the alternative Admin Theme first before you check the Theming information. Otherwise, you'll never find your template highlighted since there's no such template in your alternative Admin Theme folder.

disandov’s picture

@happydrupal

it worked!! you were right. The right template was highlighted in bold, in the "Theme: Information" settings under "Basic Settings" in the Edit Views Page. Of course, i had to Rescan Template Files before it worked.

thanks a lot,
D.-

merlinofchaos’s picture

Status: Active » Fixed

I just checked a fix into Views dev that will allow you to access the raw argument input via !1 (paired with %1 to get the argument title).

kenorb’s picture

Thanks!

happydrupal’s picture

OH..............Great thanks!!!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

joerns’s picture

Thanks a lot!