DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

TokenReplace

 6 Replies
 2 Subscribed to this topic
 26 Subscribed to this forum
Sort:
Author
Messages
Advanced Member
Posts: 233
Advanced Member
4 Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
New Poster
New Poster
Congrats on posting!
4 Engaged Reader
Engaged Reader
You are an engaged reader!
Trying to clean up and centralize token replacement in the forums module and use the Tokens Service in DNN. No problem getting the service and property accessors wired up for [FORUM:*] tokens. That part works great.

Problem is when calling the TokenReplace method or ReplaceEnvironmentTokens method. If the source includes something that *looks* like a token but isn’t in the PropertySources, it gets removed. Example would be a [RESX:xxx] token.

If I pass in “[FORUM:FORUMNAME] [RESX:UpdatedBy] [USER:DISPLAYNAME]”. the [RESX:UpdatedBy] *should not* be removed.

Shouldn’t the API replace ONLY the tokens under its control and “known” PropertySources? Otherwise I have to replace tokens one-by-one, which kinda defeats the purpose of calling the method. Am I missing something?
Veteran Member
Posts: 349
Veteran Member
3 Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
MVP
MVP
You're an MVP!
Engaged Reader
Engaged Reader
You are an engaged reader!
Avid Reader
Avid Reader
Avid Reader art thou!
Well, in the forum implementation of TokenReplace you can define a LocalizationPropertyAccess class that will handle the RESX PropertySource and do localization and then call the ReplaceTokens method once to do everything.
Advanced Member
Posts: 233
Advanced Member
4 Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
New Poster
New Poster
Congrats on posting!
4 Engaged Reader
Engaged Reader
You are an engaged reader!

Posted By Daniel Valadas on 8/14/2024 10:50 PM
Well, in the forum implementation of TokenReplace you can define a LocalizationPropertyAccess class that will handle the RESX PropertySource and do localization and then call the ReplaceTokens method once to do everything.

Thanks your suggestion. I actually did that already as a quick workaround. My concern is how to know/guarantee that valid but unknown token-looking content isn’t removed? I can guard against what I know, but should the API really remove token strings beyond known property sources?
Advanced Member
Posts: 233
Advanced Member
4 Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
New Poster
New Poster
Congrats on posting!
4 Engaged Reader
Engaged Reader
You are an engaged reader!

This would be my recommendation -- let me know if you agree, and I can put in a PR?

1. Capture the original token, and pass to replacedTokenValue function:

2. Return the original token rather than string.Empty when a match isn't found

 

Veteran Member
Posts: 349
Veteran Member
3 Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
MVP
MVP
You're an MVP!
Engaged Reader
Engaged Reader
You are an engaged reader!
Avid Reader
Avid Reader
Avid Reader art thou!
Well IMO that would be a massive breaking change. Maybe an overload with keepUnkownTokens Boolean would be best.
New Around Here
Posts: 3
New Around Here
Is there a way to add custom PropertySource without changing the Html module source code?
Veteran Member
Posts: 349
Veteran Member
3 Helpful Replier
Helpful Replier
Thanks for being such a helpful replier!
MVP
MVP
You're an MVP!
Engaged Reader
Engaged Reader
You are an engaged reader!
Avid Reader
Avid Reader
Avid Reader art thou!

I am not sure I understand what you mean by that.

These Forums are for the discussion of the open source CMS DNN platform and ecosystem.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
  2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
  3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  5. No Flaming or Trolling.
  6. No Profanity, Racism, or Prejudice.
  7. Site Moderators have the final word on approving / removing a thread or post or comment.
  8. English language posting only, please.

Would you like to help us?

Awesome! Simply post in the forums using the link below and we'll get you started.

Get Involved