Is it possible to use "regular" tokens in a views global custom text field? Could it be? I am trying to use something like [site-name] - I know I can use the "replacement patterns" from other fields in my view but I also want to use other tokens.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ilbeppe’s picture

Subscribe!

Dave Reid’s picture

Status: Active » Fixed

Yes, if you're using a 'Global: Text area' with a text format that has the token filter enabled for it, then it should replace tokens just fine.

Status: Fixed » Closed (fixed)

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

cluther’s picture

But how do you get Global: Text Area in the fields section? I can add a "Global: Text Area" field in the Header section of a view, and it provides the Text Filter option which substitutes tokens just fine. But in the row Fields section I have only the option of "Global: Custom Text" fields, which do not have the Text Filter option and therefore can't utilize the token filter.

screenshot

(Thinking that perhaps this post belongs in the Views forum, I cross-posted there. See https://drupal.org/node/2037473)

deanflory’s picture

Issue summary: View changes

I'm with you cluther on this. I find it hard to believe this hasn't been resolved yet. Is this allowed in D8?

jjmackow’s picture

I've used 'Display Suite' for dealing with this in the past. Within Display Suites' supported modules, you can created a coded field and then use tokens within the coded field to get the desired result within the list of fields for a view.

deanflory’s picture

Thanks jjmackow! That was actually next on my list of ways to try and get this to work.

deanflory’s picture

I think moving this to Views might get some more eyes on this...and reopening it.

deanflory’s picture

Project: Token Filter » Views (for Drupal 7)
Version: 7.x-1.x-dev » 7.x-3.x-dev
Component: Documentation » Code
Category: Support request » Feature request
Status: Closed (fixed) » Active
truls1502’s picture

It would also be great if it is possible to use tokens on "Title > Title"

Anybody’s picture

I can confirm that, as described in #4 this is a bit inconsistent and there are some cases when it would definitely be helpful to have that option. Does someone know a contrib module for that until it might be in views core one day?

lincolnbergeson’s picture

This would be a really great feature!

Yuri’s picture

Someone used the Advanced Text Formatter for this purpose..
https://drupal.stackexchange.com/questions/178576/is-it-possible-to-use-...

truls1502’s picture

But it would be great if it is possible to have included in Views-module, right?

P.Selfin’s picture

Comment #14
Absoulutly!

JoshuaBud’s picture

The suggestion in #13 does not work for the Global: Custom Text field. This is a functionality that I have seen requested over the last 6-8 years in various forms and in various issues. I just don't understand how utilizing tokens either core or custom in my case is not supported.

If the Global: Custom Text field were changed to a 'Unfiltered Text' field as is found in the Views 'Header'/'Footer' Global: Unfiltered Text this would allow for Tokens to be used.

dualcorpse’s picture

Someone here adds a simple field type that extends Global : Custom text. As pointed by bjmiller, it's works when overriding the render_tex method.

https://stackoverflow.com/questions/9769798/current-date-token-in-drupal...

roman.haluska’s picture

Status: Active » Needs review
FileSize
674 bytes

Attached patch is adding global token support for views global textarea.

klausi’s picture

@roman.haluska: but the token support can already be configured in the text format that is then used in the views_handler_area_text class. Should we change the views_handler_area_text_custom class instead to do token replacements there? It has no text format, so token replacements would be appropriate?

klauq’s picture

Hi
So do we have this settled? I think should have been a default feature in views, I am very suprised we don't have this yet.

Thank you!

stemiwe’s picture

A workaround that worked for me is using view in view to get the desired tokens into a field.

For example, I wanted to get the [ current-user:uid ] token, so i made a view "current user", which displays user ids with a contextual filter that filters for currently logged in user.

Then i embedded this view into a custom text field using twig
{{ drupal_view('current_user', 'page_1') }}

Just don't forget to select "strip html tags" under "re-write" for your text field, otherwise you get all the markup of the view.

ma74’s picture

For some purposes, like relative dates, you can do this with twig. ie
{{"now +1 day"|date("m/d/Y") }}

liquidcms’s picture

At least for D8, even though this shouldnt be required (it should be part of Views) - as the views Custom Text field supports twig, if you install the Twig Tweak module you can do this {{ drupal_token('site:name') }}

riazsaid15’s picture

Thanks, liquidcms. #23 worked like a charm. It saved my day.

Harry Slaughter’s picture

#23 does work. Thanks for the workaround.

Giuseppe87’s picture

On Drupal 10.1.x trying #23 I get the error:

Twig\Error\SyntaxError: Unknown "drupal_token" tag in "__string_template__d63e10f79d9d43968f5ae212f85498f7" at line 1. in Twig\Parser->subparse() (line 160 of /var/www/html/vendor/twig/twig/src/Parser.php).

The above solutions did need something else or worked out of the box?

Just to be clear: twig tweak is installed, if I print {{ drupal_token(something)) }}on a normal twig file, it works.