Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Token Replacement ExampleToken Replacement Example
Previous
 
Next
New Post
12/10/2008 9:07 AM
Accepted Answer 

ok, here is what I did in the Page_Load using C# to replace a label with the content of a string with Tokens


                // Create the string with Tokens
                String strContent = "<div id='test'><a href='[WEBORIGIN]' target='_blank'>[user:firstname]</a></div>";
                // 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)
        {
            this.UseObjectLessExpression = true;
            this.PropertySource[ObjectLessToken] = _TRInfo;
        }

        public string ReplaceMyTokens(string strSourceText)
        {
            return base.ReplaceTokens(strSourceText);
        }
    }
}
 


If you have all of that you can have your module up and running in no time. Hope someone finds all of this interesting...

 

kind regards,

Orlando Frooninckx

http://www.weborigin.be

 
New Post
1/23/2014 5:41 PM
 
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);
}
}
}



 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Token Replacement ExampleToken Replacement Example


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

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

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. 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.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out