Closed (fixed)
Project:
View reference
Version:
6.x-2.9
Component:
User interface
Priority:
Normal
Category:
Task
Assigned:
Issue tags:
Reporter:
Created:
30 Jan 2009 at 19:07 UTC
Updated:
2 Feb 2009 at 22:38 UTC
How to pass the node title or node name as arguments to a view?
PHP for the view reference field is enabled.
I tried print $node->title; or print $node->name; - but doesn´t seem to work :-(
Passing the arguments in clear text works. :-)
Drupal 6.9, View Reference 6.x-2.9
I have only poor knowledge about php.
Thanks for any help.
Comments
Comment #1
danielb commentedThe first one should work if you are editing a node, but not at node creation. Have you tried debugging your code with something like
drupal_set_message("<pre>".print_r($node,true));to see if $node->title has a value at the time the code is run?Comment #2
ksc commentedI put your suggested code in the argument field. It brings an empty line (li-formated) under the message saying that the file has been updated.
Moving the field (weight) beyond other fields of the node brings no solution.
As I already wrote: passing the arguments in clear text works fine. All HTML Filters are disabled.
Checking the data with "contemplate" gives no more information to me. The php-print command ist shown under "$node->field_testview[0]['arguments']" and under "$node->content['field_testview']['field']['items'][0]['#item']['arguments']"
Any more ideas? Do you have experience in passing the node-id as argument to a view?
Thanks for your support!
Comment #3
danielb commentedMy only other idea is to put this before your other code
There is actually a more 'proper' way to do this with the menu functions, but I can't remember it.
Comment #4
ksc commentedYIP! :-) Works.
To pass the node->title and the node->name (person who created the node) to the referred view, I use the following php-code as an argument in the view reference field:
One can change $node->title or $node->name to every field type a node contains (I believe).
(Would be helpful for others to have this in the documentation)
To understand how I use it:
I have a node type "seminars" with which users can describe their seminar content.
A second node type is for "seminar-dates" which has a node reference field to "seminars".
With a view (and filters) visitors can search for seminar-dates and seminar-types. When they use the link to the "seminars"-node, they originally see only the content. With the view reference field in the "seminars"-node (and the arguments above and naturally a "view" for it) they now see a list of dates for the actual seminar WITHIN THE NODE.
I found various forum topics also in the German drupalcenter.de where people were searching for such a solution (without using much programming) - here it is.
Daniel, I have three suggestions for the view reference module:
1) It would be nice to have a switch for the view reference field like:
- users can see and edit field content - OR - apply only default values
I my case I don´t want to give users access to that field while editing the node.
( I know, that could be done with CCK-content-permission. But I have a lot of CCK fields and a lot of user roles. So I don´t want to open the box of pandora and loose the overwiew over the permissions.)
2) The titel of the view within the node is the views name. I would prefer to have the views page titel there.
3) While editing basic field information:to me it looks easier to have the default values for arguments in the group "arguments".
Again - thanks for your support!
Klaus
Comment #5
danielb commentedI am interested in your 2nd suggestion. The content permissions one you shoudl really do with content permissions - I don't want to double up on the permissions in my module too - then people have to remember to tick both permissions, and will get annoyed at me.
The argument default values being under the default values fieldset is automatically done by CCK, I didn't put it there. Most people would look for it there probably.
But the 2nd one - I didn't think of that I guess, you can probably fix it with a theme function. I will assign as a task for me to look into.
Comment #6
ksc commentedI understand your point ref. suggestion 1)
I installed "content permission", gave users the right to view but not to edit a view reference field I defined beforehand for a nodetype. I set the defaults: the view and arguments as php code.
When a user now creates a new node using this node type, the default argument (phpcode) doesn´t get stored, only the default view link.
When having edit rights everthings works fine.
But I don´t want to give users space for php code within content.
Any idea?
Comment #7
danielb commentedI will have to look into this specific use-case some time. I may also need to add permissions for allowing users to use PHP or to at least check the existing PHP permission provided by another module.
Comment #8
ksc commentedI checked the viewfield module - it does exactly what I wanted to have. It already has a switch: "Force default" If checked, the user will not be able to change anything about the view at all. It will not even be shown on the edit node page. The default value will be used instead.
The module is able to send arguments without using php code such as %nid, % author, %visitor ...
I wonder why there are two projects working on the same functions.
Comment #9
danielb commented3 modules actually - check the homepage description on this project. They use different methods and give users different tools.