How to write a token inside a custom token

Created on 4 October 2019, over 5 years ago
Updated 3 February 2025, 3 months ago

Hi there,

how can I nest tokens from available tokens inside a custom token?

From the custom_tokens documentation I found the script about domain-access awareness of a custom token.
Very Basic Custom Token with Domain Access

I need help in PHP coding to write an existing token into my custom token.

My use case:
I have 2 domains (domain access) and 3 languages (de/cz/pl).
Domain 1: cz/de
Domain 2: pl/de

The problem is, that content in /de differs at some parts (taxonomy description) on the domains.
Domain1/de > tax description > "jobs in Tschechien"
Domain2/de > tax description > "Jobs in Polen".

I´ve created an additional custom field in the vocabulary ( [term:field_description_pl] )
I need to display it only at domain2, when in german (de) language.
On domain1/de the default description field must display ( [term:field_description] )

This is the script which works when adding just text string:

global $_domain;
if ($_domain['domain_id'] == 1 ) {
  $basic_token = 'Some text for domain one';
  return $basic_token;
  }
else {
  $other_basic_token = 'Some text for domain two';
  return $other_basic_token;
  }

I don´t have much skills in PHP coding ... can someone help me to exchange:

'Some text for domain one'

with the available token [term:field_description_pl]
..and of course the same for domain2.

I will then put this custom-token into the metatags field, what works with this code above with the text strings.

I couldn´t find other solutions for metatags - domain sensitive.

thanks in advance

Vincent

💬 Support request
Status

Closed: outdated

Version

2.0

Component

Documentation

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024