Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#18 | views-token-support-1417266-18-D7.patch | 674 bytes | roman.haluska |
|
Comments
Comment #1
ilbeppe CreditAttribution: ilbeppe commentedSubscribe!
Comment #2
Dave ReidYes, 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.
Comment #4
clutherBut 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.
(Thinking that perhaps this post belongs in the Views forum, I cross-posted there. See https://drupal.org/node/2037473)
Comment #5
deanflory CreditAttribution: deanflory as a volunteer commentedI'm with you cluther on this. I find it hard to believe this hasn't been resolved yet. Is this allowed in D8?
Comment #6
jjmackow CreditAttribution: jjmackow commentedI'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.
Comment #7
deanflory CreditAttribution: deanflory as a volunteer commentedThanks jjmackow! That was actually next on my list of ways to try and get this to work.
Comment #8
deanflory CreditAttribution: deanflory as a volunteer commentedI think moving this to Views might get some more eyes on this...and reopening it.
Comment #9
deanflory CreditAttribution: deanflory as a volunteer commentedComment #10
truls1502It would also be great if it is possible to use tokens on "Title > Title"
Comment #11
AnybodyI 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?
Comment #12
lincolnbergeson CreditAttribution: lincolnbergeson commentedThis would be a really great feature!
Comment #13
Yuri CreditAttribution: Yuri commentedSomeone used the Advanced Text Formatter for this purpose..
https://drupal.stackexchange.com/questions/178576/is-it-possible-to-use-...
Comment #14
truls1502But it would be great if it is possible to have included in Views-module, right?
Comment #15
P.Selfin CreditAttribution: P.Selfin commentedComment #14
Absoulutly!
Comment #16
JoshuaBud CreditAttribution: JoshuaBud commentedThe 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.
Comment #17
dualcorpse CreditAttribution: dualcorpse commentedSomeone 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...
Comment #18
roman.haluska CreditAttribution: roman.haluska commentedAttached patch is adding global token support for views global textarea.
Comment #19
klausi@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?
Comment #20
klauq CreditAttribution: klauq commentedHi
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!
Comment #21
stemiwe CreditAttribution: stemiwe commentedA 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.
Comment #22
ma74 CreditAttribution: ma74 commentedFor some purposes, like relative dates, you can do this with twig. ie
{{"now +1 day"|date("m/d/Y") }}
Comment #23
liquidcms CreditAttribution: liquidcms commentedAt 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') }}
Comment #24
riazsaid15 CreditAttribution: riazsaid15 commentedThanks, liquidcms. #23 worked like a charm. It saved my day.
Comment #25
Harry Slaughter#23 does work. Thanks for the workaround.
Comment #26
Giuseppe87 CreditAttribution: Giuseppe87 commentedOn Drupal 10.1.x trying #23 I get the error:
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.