Is there a service in Orchard CMS that will resolve any tokens on a given string?

StackOverflow https://stackoverflow.com/questions/22791731

  •  25-06-2023
  •  | 
  •  

Question

Let's say I have a string, and in that string there could be none, one or many Tokens (eg {User.Name} etc...).

Is there a service that I can inject that is capable of resolving any tokens that are found in the string? Something along the lines of: _tokenService.Resolve(myString);

I've had a look in the Orchard.Tokens module, and unless I'm mistaken, it would appear that the closest to this kind of service would be ITokenizer.Replace(string text, object data), where the data argument is a collection of tokens.

Am I responsible for pulling the tokens of of my string and passing them to this service? Or am I missing something?

Était-ce utile?

La solution

data is not a collection of tokens. It's the context in which the tokens will get evaluated. For example, this is where you would pass in the content item that will provide the context for all Content.* tokens. ITokenizer is the API to use, and yes, the caller is responsible for passing in the context. Otherwise, a default context may be used (the current user in the case of User tokens for example), but it may not always be what you expect. If you described the actual scenario where you want to use this, I might be able to give better advice. You can also read this to get some more context about the feature:

http://weblogs.asp.net/bleroy/archive/2011/07/22/future-orchard-part-1-introducing-tokens.aspx http://weblogs.asp.net/bleroy/archive/2011/07/27/future-orchard-part-2-more-tokens.aspx

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top