- Issue created by @bcurry
- 🇨🇭Switzerland berdir Switzerland
You're mixing up quite a few different things.
The most important one being, token and twig have absolutely thing in common, they are two completely different systems, you can't use nor do you need to use tokens in twig templates.
In twig templates, you have direct access to the relevant objects, so in a node template, you have access to node and access methods and fields. In your case, there's a method for accessing the user/owner of a node, so that would be {{ node.getOwnerId }}.
You didn't specify if you want the current user UID or the node author, but I'm assuming the second. The current user would be quite bad for caching as it would be different for every authenticated user, then you need to consider cache contexts and things get more complex.
Also, this module adds a token UI and more tokens, it does not support replacing tokens in content, that would be token_filter as you mentioned, so if you have a problem with that, you'll need to ask support there. That said, issues are a not a good place for support requests. Try slack, reddit, drupal stackexchange or something like that.
- 🇨🇦Canada bcurry
Thank you so much for these insights.
In Drupal 7, I had a template file (node--myContentType.tpl.php) which used PHP to add logic based on $user->uid to a node. Online PHP to twig converters suggest that references to $user->uid would convert to user.uid in twig. Trying to reference the user's uid is what led me to Tokens.
I'm pleased to see {{ node.getOwnerId }} does show in my node, but I actually need the user's uid not the author's. If anyone could point me in the right direction to adding that to a node would be greatly appreciated. Apparently adding [user:uid] to the body of an article through the Token module is not an option in Drupal 11.
- 🇨🇭Switzerland berdir Switzerland
You can make the current user information available in your template with preprocess: https://www.drupal.org/docs/8/theming-drupal-8/modifying-attributes-in-a... → , so you implement preprocess, call \Drupal::currentUser() and store its id there.
The problem as mentioned is caching. Drupal 8+ cache tons of elements automatically and it doesn't know that it depends on the current user. That's where things get more complicated.
The quickfix would be to do https://stackoverflow.com/questions/42166081/preprocess-node-is-entered-..., tell it that it depends on the user cache context and then it works. by by making each node type unique to user, you will create a cached version of every node for every user and mostly break dynamic page caching as that refuses to cache for each unique user.
More complex solutions involve using lazy builders to embed the part that''s per user dynamically later on, but I don't know what you're doing and we're already way, way outside of the scope of "token support". I suggest you use one of the mentioned channels above and actually describes why you need that user id I assume it's not only the ID you need but that you want to do something with it, and there might be better approaches to do this. You could post a link to that question and I might follow-up there
Automatically closed - issue fixed for 2 weeks with no activity.