Hi,

This might be a general D7 theming question, but I was wondering what the $title_prefix and $title_suffix variables are all about in page.tpl.php.

The description says:

* - $title_prefix (array): An array containing additional output populated by
* modules, intended to be displayed in front of the main title tag that
* appears in the template.

Which modules would use this and how would they implement it? Is this used to implement html tags around the title? Or could it be anything - like images or so?

Cheers,
Danny

Comments

danny_joris’s picture

So it seems that 'contextual links' is the most important use for this. http://drupal.org/update/themes/6/7#title-prefix-suffix

If there are any other use cases, I'd love to know.

barraponto’s picture

there is the "add shortcut" link, as well.

johnalbin’s picture

Status: Active » Fixed

Yep. :-)

Status: Fixed » Closed (fixed)

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

deva1983’s picture

Version: 7.x-3.x-dev » 7.x-5.1
Component: PHP Code » PHP/JS code

Hey there,

Not sure if bumping this old thread is the way to go, but I thought the subject fit my question quite nicely.
I've been trying to use $title_prefix and _suffix in my template, in order to prefix/suffix all titles of a specific content type with set strings.

i.e. "I like to " "get down in the mud" " and get dirty like peeg!"

So I populate them in my module more or less like so:

function MYMOD_preprocess_node_TYPE(&$variables, $hook) {
  $variables['title_prefix']['MYMOD'] = array('#children' => t('I like to '),
                                              '#prefix' => '<span class="MYMOD-prefix">',
                                              '#suffix' => '</span>',
                                              );

  $variables['title_suffix']['MYMOD'] = array('#children' => t(' and get dirty like peeg!'),
                                              '#prefix' => '<span class="MYMOD-suffix">',
                                              '#suffix' => '</span>',
                                              );
}

In teaser view, they get added all right. However in page view, the title is provided by page.tpl.php with those vars unpopulated, and the ones that I have set appear on their own after the tabs.

Now, ok, I understand how this happens, and I've read about how http://drupal.org/update/themes/6/7#title-prefix-suffix proposes to render those even when the title is not. I also see how there's no conditional logic relating to $node in page.tpl.php, and that's neat, too.

However, in this case, the title rendered by the page template is actually the node title, and the _prefix and _suffix end up just being pieces of content with misleading names.

So I was wondering whether this is intended behavior or if maybe those vars are not for my use case at all. I mean, for the purposes of my project I could just hardcode the strings in the templates themselves and save myself some CSS trouble too.

Or would it make sense to print the node's title_prefix and _suffix instead of the page's when there's an automatically loaded one on a page template?

I haven't actually managed to get the var from the page template (maybe _preprocess_node hasn't ran at that point? I'm not a total noob but a noob nonetheless) but I would be happy to try my hand at a patch if someone pointed me at the right direction. And if my take on the subject makes any sense, of course.

barraponto’s picture

If you want a variable to be available in page.tpl.php, you probably need to set it in preprocess_page instead of preprocess_node.

deva1983’s picture

Yeah, figured that much. What I was talking about, however, was whether the implementation of title_prefix and title_suffix is supposed to work this way.

In full node pages, the page title becomes the node title, while the node title is not displayed. Wouldn't it be reasonable for it to get the node's title_prefix and _suffix too?

Currently if I want to wrap node titles in prefixes/suffixes both in node and teaser views, I have to populate both page titles with _preprocess_page for full node views and node titles with _preprocess_node for teaser views.

Just asking if that behavior is intended.

durum’s picture

bump

jeebsuk’s picture

Issue summary: View changes

I would also be interested to know about an answer to this as I've been experimenting with these properties over the last day or so with absolutely zero success thus far.