Hi all,

So I feel like this should be really easy to do, or at least I did when I started trying hours ago, but I may be wrong.

So I have a view the displays a recipe that a user has entered. Is there a way to set the Basic Setting: Title to be the Node: Title?

I think I'm just not seeing where this is set and the header is built.

Thanks,
Tristan

Comments

nevets’s picture

Are you saying a single recipe? Why not just display at node/{nid} where {nid} is the node id?

mcfilms’s picture

I think (and I'm just THINKING here) that setting the Title in Basic Settings: Title Gives you a fixed title. You could name it "Recipes" and if you print 10 recipes, this would be the header. If you are trying to get 10 recipes and each one to have the dynamic title, you might want to include the Node: Title as a field -- along with whatever else you are displaying. So each of the 10 would be Titled"Spinach Pie" "Beef Stew" etc.

Capiche?

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

tristanmatthews’s picture

So I have the node title field included, but I can't see how to set the basic setting of title to the value of the field for each recipe. So I can call it Recipes and they are all called that, and then do a title under it with "spinach pie", but I feel like it would be much cleaner if I could set the title to the node title for all of them. That way you not only "spinach pie" on the page, but as the page title and so forth.

mcfilms’s picture

One more thing that might help....

The default display in views is just a node. Look along the left edge of the window and add or see if there is a "Page" view. You may only be looking at the node view. (I don't know how much I am helping as I am a Views novice myself.)

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

tristanmatthews’s picture

Thanks mcfilms, but its a page already.

A lot of the fields can do things with string replace like use [title] to insert the title, but that doesn't seem to work with the basic settings, so who know. I'm sure I'll figure it out...

nevets’s picture

It really seems like you want to list nodes not fields.

That said, if you add "Node: title" as a field it displays the label (Title by default) and the title for the current node so am no sure what "So I can call it Recipes and they are all called that, and then do a title under it with "spinach pie"," refers to.

As for "That way you not only "spinach pie" on the page, but as the page title and so forth." once again it sounds like you are trying to display a single node (not a list) in which case using the nodes path may be more appropriate.

tristanmatthews’s picture

Hi Nevets,

Thanks for the replay, and yes I am just displaying a single node worth of data, but I'm using a some of views features for the display, and what fields are shown. Since I have a number of ways to look at each recipe based on who you are and how you get there this seemed like the easiest thing to do.

So when I set the basic settings title it displays at the top of the main content part of the page, in the title tag, in the header, and in the bread crumbs trail. It looks like there was a "not to bad" way to do set the title tag, and bread crumbs with views 1, but I can't figure out how to do it in views 2, with out using the basic settings.

nevets’s picture

Why not use CCK permissions to determine who can view what fields and/or theming in node-{content_type}.tpl.php (replace {content_type} with your content type), this seems easier to me.

tristanmatthews’s picture

Besides, I can think of an number of other reason I would want to be able to do this, so...

amfis’s picture

I think he meant html page title.

MjrNuT’s picture

But this is what I followed to accomplish exactly what you are talking about.

http://www.davidnewkerk.com/book/18

I just replaced the word Articles with Recipes

Now I'm trying to take it a step further, which looks like others are interested as well: http://drupal.org/node/612468

yevonsoul’s picture

I don't know if this is the right one but I think we share the same problem. I have a view that has a static title. I also have a taxonomy term which is based on views. What I want, is when I click on the taxonomy term I would also get that taxonomy term as the title on the page view.

How can I do this?

betz’s picture

looking for the same

therealwebguy’s picture

Subscribing

arski’s picture

me too! This shouldn't be too hard given that it's possible to use the replacements like [fieldname] almost everywhere else.. then why not in the title.

Thanks!

dougvann’s picture

subscribing
I'm looking in to some custom code to get this done.

See you at the The Do It With Drupal Seminar
Learn from the Lullabot Drupal Video Series

arski’s picture

Hi guys,

Just so you know - this has been fixed by the Views people a while ago, see http://drupal.org/node/397358

I guess this is really a wrong place to post module-specific bugs/feature requests :)

Enjoy!

scottprive’s picture

Hi,

Your link is a solution to a different type of problem. This problem does not involve Node Reference.

There are a number of reasons why you would want to dynamically set View Title based on -any- field or fields from your view results. Node.Title would be the most useful example field, but it is not the only field which would be useful in a title. The fact is, values from view results are not made available (at all) to anything in the Basic Settings area (not just View Title).

This does not mean that there is no solution at all. There is.

One solution that DOES work is to export your view (which you should do anyways for performance reasons). When the view is exported, you can edit the Views API code and set the page title that way. Depending on what you are doing for content, you MAY need to duplicate the same SQL query in your PHP (to arrive at the correct field[s]), then prepare a string for the title, then send that simple string as a Views API argument. Problem solved.

Not everyone wants to export their view, or folks do not want to do this during prototyping so that is one reason why this issue keeps coming up.

Also, Solving this in Views UI would allow you to dynamically set page titles in Panels also. Panels may set Page title based on a hardcoded value, Views Context (which does not work for this, due to argument context issue), or a hardcoded title string, OR.... Views Title. You can tell Panels to use the view pane's view title, and it works great. The core problem in that scenario is on topic to the original poster's problem of dynamically setting View Title (since an easy solution here would solve that issue also).

On IRC, Earl told me the re: views title issue: "The reason view titles can't use field data is mostly that it's never been done, and that using field data as part of the view title is generally only relevant with single row views."

Based on that answer, I would assume it will be done someday but it is not the most pressing priority (and for sure, there is a lot of development going on).

So for folks struggling with this or similar problems: Export your View
It is important to remember that Views UI is not Views. What I mean is, the Views UI is like a "wizard" that helps you do common tasks and it can shield you from PHP, most of the time.

The Views API (and the Views template layer) can do so much more than the Views UI. (One off-topic example to support this would be, some folks ask how to dynamically set the "Items to display" based on an argument. Views UI can not do that. But once you export the view, you can get the argument somehow in PHP, then pass that in as an argument to the Views API call, and this works.)

Hopefully this helps someone. For now, you can solve this, but only in code and not any GUI settings.

hiteko’s picture

You can put php code in the "Header" part of "Basic Settings", like:

$view = views_get_current_view();
if($view->result[0]) {
    drupal_set_title($view->result[0]->title);
}

This will set the page title dynamically.

Hope this helps.

willhowlett’s picture

This worked for me, though I used node_title instead. Thanks for posting.

<?php
$view = views_get_current_view();
if($view->result[0]) {
    drupal_set_title($view->result[0]->node_title);
}
?>
tarzadon’s picture

I also used node_title and it worked for me.

Thanks!

D2ev’s picture

In Style output tpl file you can set the title based on -any- field or fields from your view results.
use $view variable to get the result set

 drupal_set_title($view->result['0']->node_title);
Omar Alahmed’s picture

The title could be dynamic without changing the views.tpl file or any altering code, if you want the title to be dynamic, this means that the page path will be dynamic, and this could be set from the view arguments and there you can set the page title as pattern i.e: %1 and depends on the page path the title will be.

and there is another way using this http://www.zyxware.com/articles/644/change-the-page-title , but I recommend the first solution.

jjjames’s picture

Yes Omar you are correct! I believe this is the solution lot's are looking for.
Thanks!

savedario’s picture

Indeed it works. If only the field description was explaining that much...

sushantpaste’s picture

For D7 we can do it in view Advance ->contextual filter.have options to Override title .so we will able to Override the view and other argument titles.like %1 first argument.
Hth

drupalshrek’s picture

For full control over the title, this is what I do:

Define the path you want using hook_menu(), e.g.

/**
 * Implements hook_menu().
 */
function lp_rank_menu() {
	$items = array();

	// The content for this tab will come via a function pulling in the view contents
	$items['flipcard/quiz/%/rank-detail'] = array(
			'type' => MENU_LOCAL_TASK,
			'title' => 'Rank Detail',
			'page callback' => 'drupal_get_form',
			// Parameter 2 is taxonomy id
			'page arguments' => array('lp_rank_words_by_rank_detail', 2),
			'access arguments' => array('flipcard admin'),
			'description' => 'Get the words by rank for a lesson.',
			'weight' => 100
	);
	
	return $items;
}

Then in the page callback, embed the view, e.g.:

/**
 * Prepare a list of words for a given lesson
 */
function lp_rank_words_by_rank_detail($form, &$form_state, $tid) {
	global $user;

	$form = array();

	$form['words'] = array(
			'#type' => 'item',
			'#markup' => views_embed_view('lesson_words_by_rank', 'words_by_rank', $tid)
	);

	flipcard_set_lesson_title($tid);

	return $form;
}

Then you can have full control over the title and use drupal_set_title(), e.g.

/**
 * Set the lesson title
 */
function flipcard_set_lesson_title($tid) {
  $taxonomy_name = flipcard_taxonomy_name($tid);
  $lang_name = flipcard_lang_name();
  drupal_set_title($taxonomy_name . ' ' . $lang_name . ' lesson');
}

drupalshrek