I'm trying to bubble up the node title to the view title. I can dive down from a url arg and change the title of the view using a view argument. I was hoping I could do something add some php code that reads the node loaded and sets the title.
I fiddled and found I can enter php code into the header section of the view. I tried invoking drupal_set_title("mytitle") but it didn't work and I don't how to access the node since $node isn't loaded with the page.
In case you're wondering why its being done this way? The view is a content_pane that inside a panel and the panel is set to read the view title but the view title needs to be the node title. I'm sure there is a better way but at the time this worked for statically titled views. Now the pages titles are supposed to dynamically change based on the node title through the view.
Thanks
edited by silverwing - changed forum
Comments
Does the view return only a
Does the view return only a single node? Does the view take a nid as an argument?
The view returns a single
The view returns a single node and has no nid argument. It displays the most recent node in the view of a specific type. The rest of the nodes loaded into the panel below it are static but the view determines the page title using title type from pane.
Recently discovered I can grab the title that I need using but I'm sure when I do this it takes another spin through the database which won't be a good solution live but I thought I'd post it incase it helps.
but drupal_set_title($node[0]->node_title) doesn't work...
I ended up adding an argument
I ended up adding an argument to the view; node: title, set title to be replaced by %1 (first argument) set a default argument, selected use PHP Code, added this code...
as my php argument code. It sets the page title, unfortunately also sets the pane title which for some reason can't be turned off even though it says it is, so I added a css id to the panel and hid the pane title separately. It also hits the database twice I'm almost positive so that's pretty lame.
So not happy with it by a long shot but it allows me to keep working. If anyone finds a better solution to bubble up the node title to the page I appreciate any better solutions but it works for now.
Thanks
When you specify an argument,
When you specify an argument, you can set the title, for Node: nid, %1 should be the title.
Absolutely, the argument I
Absolutely, the argument I put in place just sets the title using %1 but it uses default php argument code that recalls the view and returns the first nodes title using the code snippet above. There's no url argument to use so it's being faked by default and the view is being called twice to set the title. Once to display the content and again in php argument code in the view argument to set the title of the page. Does this solution seem bad? really bad? or acceptable?
I believe even if you use the
I believe even if you use the default to return a nid, that will set % correctly. I don't see a reason to call the view twice.
Sweet your totally right.
Sweet your totally right. Thanks :)
Can you elaborate?
This is exactly what I'm trying to do. I have tried your example but it still doesn't work.
Using node title as a an argument requires a node title as the argument?
Providing a default argument of one of the node titles will display that node and set the title to that node.
Can you let me know how to fool it into displaying the title of the node from the result?
Thanks in advance...