Smarty plugin - Example

Post Affiliate Pro allows to create custom smarty plugins. The plugin will affect variable replacement in templates. This is very useful when you want to change default behaviour. During this tutorial we will make simple plugin, that will change the variable by replacing some string in it.

In the example I will use variable '$sale_approve_link' from 'Merchant - new sale/lead' email template. Let's assume that our PAP is using 'https://' url. In default behaviour the variable will be filled with ''.

But we want to remove ssl protocol, and change it to

1. Setup the email template:

First you have to create plugin name. For this purpose I will use 'https_to_http' name. It is very important to remember this keyword.

Now replace {
$sale_approve_link} variable with modified one: {$sale_approve_link|https_to_http}. In general modified variable has to match following format:

{$variable_name|plugin_name} (separated by pipe '|')

2. Create plugin:

Name of the plugin file has to match format 'modifier.plugin_name.php', so this plugin file will be 'modifier.https_to_http.php'.

In plugin source code must be a function that describes its behaviour. In our example we will replace string 'https://' with 'https://'. Complete source code:


* Smarty |https_to_http modifier
* Examples:
* <pre>
* {$sale_approve_link|https_to_http}
* </pre>
* @author Ivan Ivanco
* @param string
* @return string
function smarty_modifier_https_to_http($link)
return str_replace('https://', 'https://', $link);
Again, function name has to match following format 'smarty_modifier_plugin_name($variable)'.

3. Upload plugin to PAP installation:

The last step is to upload plugin to following directory: