How to render tokens in a Widget?

Hi all,

I am developing a widget that allows the admin to provide a chunk of HTML that will be rendered when the widget is viewed.

As part of that I have defined two insertable tokens, that the admin to insert into the HTML editor.

Here is the relevant section of the Configuration.

<property id="html" dataType="html" rows="25" template="core_v2_customTokenizedHtml">
    <propertyValue value="firstname" labelText="First Name" />
    <propertyValue value="lastname" labelText="Last Name" />
</property>

Q: In the widget code, how can I replace those token with the actual values (that I grabbed from elsewhere)?

Is there an API for that, or do I just need to do a search and replace for "{firstname}" and "{lastname}" in the HTML?

Thanks.

Parents
  • That's an interesting question.......

    Here is a sample which may help based on your config 

    <property id="html" dataType="html" rows="25" template="core_v2_customTokenizedHtml">
    <propertyValue value="firstname" labelText="First Name" />
    <propertyValue value="lastname" labelText="Last Name" />
    </property>

    with the jsm widget code something like this 

    var tokens = {
        firstname: "Karl",
        lastname: "Barber"
    };
    
    var body = core_v2_language.FormatString(core_v2_widget.GetHtmlValue('html', ''), tokens);


    or velocity would be something like this 


    #set($tokens = "%{ firstname='Karl' , lastname='Barber'}")
    #set($html = $core_v2_language.FormatString($core_v2_widget.GetHtmlValue('html', ''), $tokens))

Reply
  • That's an interesting question.......

    Here is a sample which may help based on your config 

    <property id="html" dataType="html" rows="25" template="core_v2_customTokenizedHtml">
    <propertyValue value="firstname" labelText="First Name" />
    <propertyValue value="lastname" labelText="Last Name" />
    </property>

    with the jsm widget code something like this 

    var tokens = {
        firstname: "Karl",
        lastname: "Barber"
    };
    
    var body = core_v2_language.FormatString(core_v2_widget.GetHtmlValue('html', ''), tokens);


    or velocity would be something like this 


    #set($tokens = "%{ firstname='Karl' , lastname='Barber'}")
    #set($html = $core_v2_language.FormatString($core_v2_widget.GetHtmlValue('html', ''), $tokens))

Children