Like me on Facebook Follow me on Twitter Register or    (Why?)
Demo Notes

Custom tokens are the feature that sets this script injector apart from all of the others. A custom token is a token you define inside your script by placing it within square brackets.

As a quick sample, let's say we found a small script that grabs the current weather based on country and city.

The script looks like this:

<div align="center">
<script src="http://www.weatherforecastmap.com/weather2.php?zona=canada_toronto"></script>
<a alt="forecast in Toronto" title="forecast in Toronto"
href="http://www.weatherforecastmap.com/canada/toronto" >Forecast for Toronto</a></div>

 

We can run that script as is inside Inject Anything and it will display just fine. We can also replace each occurence of Toronto with a custom token named [CITY] and each occurence of Canada with a custom token named [COUNTRY]. When we do this, the Inject Anything module will display these tokens inside the module configuration screen and we can just input our values and the values will be replaced at runtime.

Here is our new script:

<div align="center">
<script src="http://www.weatherforecastmap.com/weather2.php?zona=[COUNTRY]_[CITY]"></script>
<a alt="forecast in [CITY]" title="forecast in [CITY]"
href="http://www.weatherforecastmap.com/[COUNTRY]/[CITY]" >Forecast for [CITY]</a></div>

 

As you can see in the screen shot below, after the script is written and we click on the refesh token list link, the tokens are presented as input below where we can easily enter their values. This makes it really easy to take the customizable parts of a script prompt the administrator to just enter the new values without having to be technical. In this example I've simply entered the script in as freeform text, but in production you would probably want to create a standard script from the code so it's available to all site users.

 

 You can see the result of the script in the Inject Anything module below. Now that this script is written with tokens, I could just go back into the options for the module and change the city to Montreal etc., save the settings and now the module would show the Montreal weather.

 

Full documentation on tokens and what you can do with them is located on the wiki.

Sample for Custom Tokens

Did you know?

The following modules support and/or extend token replacement:
Privacy StatementTerms Of UseCopyright (c) 2004-2015 DNNStuff
Page generated in 0.1093778 seconds!