Oh my god this interesting topic truly lacks of documentation... there are some but not that clear and simple... i could achieve something based on this thread following the suggestion of Erik van Ballegoij(
http://www.dnnsoftware.com/Activity-F...) to Check Announcements and the code posted by Orland0 (
http://www.dnnsoftware.com/Activity-F...), There is just one addition to the code of Orland0 and was ": base (Scope.DefaultSettings)" in the TokeReplace constructor, here is the new version that worked for me, i keep the comments from Orland0 which are useful
Cheers,
// Create the string with Tokens
String strContent = "
";
// Create the object with all the information about what to replace
WO_TokenReplaceInfo TRInfo = new WO_TokenReplaceInfo();
// Pass the object to your TokenReplace object
WebOrigin.Modules.WO_TokenReplace.TokenReplace tr = new WebOrigin.Modules.WO_TokenReplace.TokenReplace(TRInfo);
// Replace the Tokens
strContent = tr.ReplaceMyTokens(strContent);
// Show the output
Label1.Text = strContent;
Basically it is not all that difficult. On thing I didn't get for a while was that the token should be typed in capitals. For completeness I will also pass the Info Class and the TokenReplace class from the App_Code section..
In the Info class all you have to do is implement "IPropertyAccess" like this:
namespace WebOrigin.Modules.WO_TokenReplace
{
public class WO_TokenReplaceInfo : IPropertyAccess
{
#region " IPropertyAccess Members "
public string GetProperty(string strPropertyName, string strformat, System.Globalization.CultureInfo formatProvider, DotNetNuke.Entities.Users.UserInfo AccessingUser, Scope AccessLevel, ref bool PropertyNotFound)
{
switch (strPropertyName.ToLower())
{
case "iamatoken" : return "A token was used and I am the result of that token.";
case "weborigin" : return "
http://www.weborigin.be";
default: PropertyNotFound = true; break;
}
return string.Empty;
}
public CacheLevel Cacheability
{
get
{
return CacheLevel.notCacheable; // CacheLevel.fullyCacheable;
}
}
#endregion
}
}
You probably noticed that in the function GetProperty there is a switch/case statement which replaces the properties you defined by the content you want to pass. Of course you can do more than just replace it by a string, but I kept it simple for this example.
The Token replace class can also be kept fairly simple. Underneat you see it's implementation like I see it.
namespace WebOrigin.Modules.WO_TokenReplace
{
public class TokenReplace : DotNetNuke.Services.Tokens.TokenReplace
{
public TokenReplace(WO_TokenReplaceInfo _TRInfo)): base (Scope.DefaultSettings)
{
this.UseObjectLessExpression = true;
this.PropertySource[ObjectLessToken] = _TRInfo;
}
public string ReplaceMyTokens(string strSourceText)
{
return base.ReplaceTokens(strSourceText);
}
}
}