2014 Nov  218  1
2014 Jul  294  2

How to create your own Token provider

Jul 13 2014



A token is string starting with a double { end ending with a double }

(without space between)

Example :

{ {tokenprovider parameter1=”value1” parameter2=”value2” ….} }

After the double { there is the token provider friendly name which is defined in the web.config.

After that you have 0..n parameters written as name value pairs respecting the xml attribute syntax.

Creating the Token Provider

Begin with creating a c# class file inn your app_code directory.

For example : MyTokenProvider.cs

Inherit from Satrabel.OpenBlocks.Token.TokenProvider

Implement the abstract method Execute.

This method have to return the content that replace the token depending on the parameters.

Now you have to add the the provider to web.config

 <add name="myTokenProvider" type="MyTokenProvider" FriendlyName="my" />


Now when you add { {my parameter="value" } } to a html module, it is transformed to "My value"

(without space between acolades)

Creating the Configurator UI

The 2nd step is to create a UI for the creation of the token in the Html Editor (accessible from the new token toolbar button).

For this you have to create a user control that inherit from TokenConfigurator and implement the 3 abstract methods.

GetToken return the token for the editor.

LoadSettings and SaveSettings is when you need to save setting like in the Token Module Settings.

Create them in "\Providers\TokenProviders\My" folder.

Then you have the complete the new line in the web.config with a Configurator attribut.

 <add name="myTokenProvider" type="MyTokenProvider" FriendlyName="my" Configurator="~\Providers\TokenProviders\My\MyConfigurator.ascx" /> 

You are finished.