Apologies if this has already been addressed, I searched 7.x issues for 'token title' and couldn't find anything that appeared relevant.
According to the release notes for views 7.x-3.0-rc1, tokens should be usable in a page display title? (Have I read that right?)
http://drupal.org/node/1192186
"#995646: Allow token substitutions in area texts and the title."
http://drupal.org/node/995646
"#15 Posted by merlinofchaos on April 13, 2011 at 9:58pm
Status: active » fixed
Ok, checked in a fix for both 6.x-3.x and 7.x-3.x that allows token use in the global text area as well as the title."
I was having problems with this in a view of mine so created a test view (see below). I had also suspected that my theme was perhaps mucking around with the title so I switched to Garland.
The test view lists a few nodes and uses a [title] token to alter the page title and global text area in the header to the title of the first node.
The results that I get are:
Preview mode with contextual filter input 'page':
Both title and header tokens are substituted correctly.
Both title and header arguments are substituted correctly.
Path with arg (test-view/page) :
Only header token is substituted.
Both title and header arguments are substituted correctly.
Do you get the same results?
Should I expect the token in the title to be substituted?
$view = new view;
$view->name = 'test_view';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Test View';
$view->core = 7;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Test View (arg %1) (token [title])';
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '3';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Header: Global: Text area */
$handler->display->display_options['header']['area']['id'] = 'area';
$handler->display->display_options['header']['area']['table'] = 'views';
$handler->display->display_options['header']['area']['field'] = 'area';
$handler->display->display_options['header']['area']['label'] = 'Header:';
$handler->display->display_options['header']['area']['empty'] = FALSE;
$handler->display->display_options['header']['area']['content'] = 'Test View (arg %1) (token [title])';
$handler->display->display_options['header']['area']['format'] = 'full_html';
$handler->display->display_options['header']['area']['tokenize'] = 1;
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['area']['id'] = 'area';
$handler->display->display_options['empty']['area']['table'] = 'views';
$handler->display->display_options['empty']['area']['field'] = 'area';
$handler->display->display_options['empty']['area']['empty'] = FALSE;
$handler->display->display_options['empty']['area']['content'] = 'NO RESULTS';
$handler->display->display_options['empty']['area']['format'] = 'full_html';
$handler->display->display_options['empty']['area']['tokenize'] = 0;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Type */
$handler->display->display_options['arguments']['type']['id'] = 'type';
$handler->display->display_options['arguments']['type']['table'] = 'node';
$handler->display->display_options['arguments']['type']['field'] = 'type';
$handler->display->display_options['arguments']['type']['default_action'] = 'empty';
$handler->display->display_options['arguments']['type']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['type']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['type']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['type']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['type']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'test-view/%';
$translatables['test_view'] = array(
t('Master'),
t('Test View (arg %1) (token [title])'),
t('more'),
t('Apply'),
t('Reset'),
t('Sort by'),
t('Asc'),
t('Desc'),
t('Header:'),
t('NO RESULTS'),
t('All'),
t('Page'),
);
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 1316932-title-tokens.patch | 812 bytes | dawehner |
Comments
Comment #1
dawehnerOh this is a bug in the ordering of the set-title function and the execution of the view.
This reorders it, so it works in the same order as the block display.
Comment #2
dawehnerCommited as it is, because this seems to fix the issue 100% and makes sense.
Comment #3
karlsheaWhat this does, however, is make it impossible to change the title in any hook I can find.
hook_views_post_execute doesn't work, and hook_views_post_render doesn't work either.
Is there another hook that executes after all of those where I can get at the title?
Comment #4
karlsheaAh, well you can do it, you just have to put it in $view->build_info['title']. drupal_set_title no longer works.
Comment #5
zenlan commentedPatched and tested, thank you for the fix. :)
Btw, for anyone interested, using token substitution from first row instead of title override:
$view->build_info['title'] would work just as well, but the substitution method allows the rest of the string to be remain configurable via Views UI.