I have a node list view for taxonomy terms. The nodes are heavily based on content taxonomy terms and also have exposed filters so the visitors can narrow down from the starting point.

Is there any way I can use for example the current taxonomy term the view is based on in the header, footer or empty setting to be able create, for example, a global header using the replacement token?

Comments

mitchell’s picture

Title: Use tokens in header/footer/empty » Token integration with views
Version: 6.x-2.5 » 6.x-2.x-dev
Category: support » feature
Issue tags: +token
StatusFileSize
new37.16 KB

header/footer/block title/etc

liquidcms’s picture

+1

lots of places tokens would be very handy in Views.. Title seems like an obvious one - and as listed above header, footer, empty text, etc

NecroHill’s picture

+1 It would be cool to have this feature

marcp’s picture

Version: 6.x-2.x-dev » 6.x-3.x-dev

Yep, this would be great. Seems like there must be a workaround for getting tokens into block titles. Anyone?

stefan81’s picture

would love to see this too

dagmar’s picture

This feature present some problems.

First, tokens are replaced from each module in special places, and views have a lot of places to make this changes.

Secondly, in order to implement this in a generic way, we should use something like translation plugin, that unpack and translate elements when they are loaded. The problem is, If we replace the token when the view is loaded, which kind of tokens will be available to replace? Only global tokens?

I don't know, maybe it can be only implemented easlily in #510284: Header/footer/empty text and more areas pluggable.

ChrisRut’s picture

+1
:subscribe:

Anonymous’s picture

+1 indeed.

boran’s picture

+1

hawkdrupal’s picture

+1111111

This would solve MANY problems and greatly reduce the need for near-duplicate views.

deltab’s picture

+1

stinky’s picture

Subscribe

kenorb’s picture

Similar #673700: tokens in title and header
Some workaround available there.

Guillaume_Desp’s picture

I think I have the same probleù but not sure...
I need to expose a token in views to filter my results but it doesn't work with views 2.
I can see the value of the token in my viewscacl table but then I can't filter.

wiredescape’s picture

subscribe

francewhoa’s picture

+1 Any volunteer for a patch?
I would be happy to contribute testing and documentation.

meatbag’s picture

subscribing

Bilmar’s picture

Subscribing - I'm needing to use tokens in the title of the views page.
http://www.screencast.com/users/trupal218/folders/Jing/media/8cddb1b1-37...

Thank you

jmseigneur’s picture

+1

dawehner’s picture

In general views builds lists of content, so a single placeholder like [node-title] does not make sense for title/header/footer/empty-text from my perspective. There is the edge-case when you have just a single item displayed.

BeaPower’s picture

subb!!!

dagmar’s picture

Status: Active » Closed (won't fix)

Lets be honest, as dereine said in #20 and I said in #6, tokens are designed to replace a single instance of items from an object.

Views displays a lots of items of kind of object. So, there is no point to provide [title] as patter of replace, due will be a lot of different titles to replace.

So please, do not subscribe anymore to this issue, at least, provide a "REAL" use case for this feature.

Bilmar’s picture

Hello,

I use views for my event pages and profile pages to show the content for the specific event as well as for differed users. I chose to use views and its template files instead of the node template files as it provides more flexibility in allowing me to use fields from other modules, set visibility settings so depending on the role I have a different display being shown, set filters to only show the page if flagged by a specific administrative flag and show the corresponding empty text, show links to change the event page to show prices and all details specific to individuals or groups done simply by linking to another display etc (the list goes on why views is awesome, hehe) Therefore I have been able to accomplish a dynamic per event and per profile page using views that can be altered depending on who the user is. For this reason I have come to realize that I'm currently unable to set the title of the page using tokens. In my case it would be the event title or user's name that I would like to use (the name wouldn't change no matter the customized version of the page, but still requiring the title to dynamically be set depending on the event title or user's name)

I hope the above use case can help add to the discussion and others can share their usecases as well.

Thank you

hixster’s picture

So please, do not subscribe anymore to this issue, at least, provide a "REAL" use case for this feature.

o.k. I would like to have a selection of post information listed under each title teaser , the same as it appear on each of my nodes. I am using the http://drupal.org/project/submitted_by module to format the post information on my nodes using tokens, which works great. I would like the same output for my teasers.
I prefer to format my teasers using the field type row style plugin, to have fine grained control as to what appears in them.

So my post info looks like this on nodes:

News Article by admin | September 19 2010 0 comments

To provide the following formatting in views, is a hassle, where as with token's it's a breeze. This is the format i use for 'submitted by'

[term] by [author-name] | [month] [d] [yyyy] [node_comment_count] comments

In views, you'd need to extract the author's name using UID, have a few hidden fields for the date and comment settings. Then to get the top level taxonomy term you need to jump through a few hoops.

gstout’s picture

+1

paul kim consulting’s picture

Here is a real use case for this feature:

Let's say you have a view that is filtered by a taxonomy term. That means that all the content in this view follows a certain constraint (in this case, a taxonomy term) that is a good candidate for tokenization to use in different places in the view (title, header, footer, "rewrite the output of this field as", etc).

Currently you cannot place such information in the Views title, for instance, without utilizing one of the Views hooks.

webwriter’s picture

Another real world use case- I am using Domain Access and would like to append the domain title to the page title to help reinforce to users where they are and to boost the SEO value.

fresheyeball’s picture

How about a global token as the value in a filter? Could be very handy.

ergophobe’s picture

provide a "REAL" use case for this feature
Let's say you have a view that is filtered by a taxonomy term.

Exactly why I was looking for this. I'm using a custom view to handle my taxonomy pages. With a full set of tokens, I could have one view and just slide in [cat] as the title and have at least generally descriptive titles on the View. Currently I set the title to empty.

ergophobe’s picture

In this thread:

merlinofchaos mentions a patch for this, but without a link. The best candidate I can find is

#811480: Additional tokens for views
But so far, still failing testing. I couldn't find any others that really address this.

See also #365418: Setting the View-Title programmatically in Views2 for some solutions to the title issue.

giorgio79’s picture

Status: Closed (won't fix) » Active

Use case:

I am using Page display, and have an exposed filter for a field. Selection is forced, and single selection.

So, for example I have services, and their types are video, search etc.

When the user changes filter, I would like the page title to use that field, eg
Video Services
Search Services

etc

Thanks :)

dawehner’s picture

Status: Active » Closed (won't fix)

This issue is about using the token module in views.

@#31
We try hard to clean the issue queue. Your feature request seems to be something like a more valid feature request then tokens support. Please create a new issue for this, it's out of scope here.
The issue would be to allow exposed filter values in other parts of views.

giorgio79’s picture

patcon’s picture

For those who want a header with tokens, just use an attachment view displayed above your page view, with a display type of Unformatted. Limit the view to one item, and load all the fields you'd want as "tokens". Exclude all the fields from display, then add a "Global: Custom text" field, and insert all the other fields as tokens.

It's pretty much the same thing as a dynamic header, as far as the user in concerned :)

Q2U’s picture

For those who want a header with tokens, just use an attachment view displayed above your page view, with a display type of Unformatted. Limit the view to one item, and load all the fields you'd want as "tokens". Exclude all the fields from display, then add a "Global: Custom text" field, and insert all the other fields as tokens.

patcon, I apologize for my Newbieness, but could you possibly elaborate on youe method? How does one "attachment a view displayed above your page view?" What is an "attachment view."

I am most interested in your method.

Thank you.

patcon’s picture

Sure thing dude.

There are different types of view displays -- block, page, attachment, feed, etc (more can be added by other modules). Each little tab on the left of the a specific view edit page corresponds to one of these view displays. You can add more or remove them, and they all sort of use the "Default" view display as a base (although you can overwrite).

So if you want a dynamic header:

  • Create a new view (which is a set of view displays with at minimum a "Default" view display).
  • Add a "Page" display and an "Attachment" display.
  • Configure your "page" display as you normally would, leaving the header blank. Set it as Table style if that's what you want.
  • Now, work on the "Attachment" display. In the "Attachment settings" portion of the edit pane, you'll be able to set it to attach to any "Page" display, positioned either below or above depending on your header/footer needs. (Override what you need to so that your changed don't affect the "Page" or "default" view display.)
  • Still on the attachment display, set the "style" to "unformatted".
  • Set the result limit to 1, so that only one row is returned. We only want one copy of the header/footer, right? (Slight aside: I'm working under the assumption that you only need data from one row in the header/footer, which is perhaps incorrect. Here's the demonstration scenario: You've got the year in the exposed filter, and you've got multiple results from multiple nodes displayed in the main table, and you have another node type that has info on that year as a whole, of which only one exists per year. This would work if you wanted that info displayed in a dynamic header.)
  • Back on track: Add all the fields you need to the unformatted attachment display, and exclude them all from the view, so they're hidden.
  • Add a "Global: Custom text" field, making sure that it's the last field in the list and that you delete its label. Assuming you have Token module installed, you can now use tokens from all the other fields to generate what amounts to a dynamic header.

Phewf. Took longer than expected to explain, but hopefully you get the idea. I haven't done this myself, but I can't see why it wouldn't work. If you need to header to disappear when values don't exist, then instead of adding a "Global:Custom text" field, you can leave one field visible and simply override it with tokens and custom text (so that it become the header). That way, you can use the checkbox to "Hide field if empty", and when that field has no value, it will hide the whole header. If that's what you're going for, I think there's also a setting in the "Attachment settings" pane that you'd need to adjust, telling views to hide the attachment if nothing is returned (but maybe I'm mistaken).

Anyhow, hopefully this helps :)
Cheers

Alexander Matveev’s picture

sub

ezeedub’s picture

@patcon Just wanted to say thanks for the suggestion. This solved a similar problem I was having.

jelo’s picture

patcon, thanks for the idea. Solved my problem!

ordually’s picture

@patcon in #36, I wanted to add my 'thanks' to the list...your writeup helped me out!

patcon’s picture

oh hey, no worries at all folks! Glad it helped :)

nodecode’s picture

patcon, this is totally brilliant!

I have a couple observations on theming this to look like normal views headers. WARNING: I'm using a Zen-based theme and I'm utterly illiterate on Drupal theming at the moment, but these are my observations so far...

1. You will need double <p><p></p></p> tags to emulate the behavior of a "Full HTML" views header which views appears to wrap in <p></p> tags. I say "use double" tags because the first set of <p> tags of a "Global: custom text" field appears to be stripped by views.

2. I haven't tried this yet because i haven't themed my site but you may want to add "view-header" to the CSS class: field as well.

Thanks again.

Some Kid’s picture

@patcon from another happy customer :-)

Brilliant!
Thanks.

stinky’s picture

Better late than never, @patcon THANKS! Your solution totally was what I needed.

emattias’s picture

Here's a patch that adds a token for every field which returns [field_name]-empty or [field_name]-not-empty string depening on if the field is empty or not.

I use this to add a "imagefield-empty"/"imagefield-not-empty" as a row class in a list of nodes that may or may not have an image. This patch works for other kinds of fields also. As long as they return something "falsy" when empty(like an empty string) and something "truthy" when not empty.

This is something I've needed on several projects and grew tired of hacking this together. So I hope that this gets commited to views asap.

emattias’s picture

Itangalo came up with probably a cleaner way of getting this functionality. His idea was to build a new views field handler which checks another field if it is empty or not and outputs whatever you want. Then you use this new fields' token.

This way you dont end up with duplicate tokens for every field.

Unfortunately I probably won't have time to make this on my current project.