Create your first Mod file |
A mod file template - with instructions.In this short tutorial we will walk through the steps required to build modification files to alter the behaviour of MrRat's Amazon Products Feed version 4. For the purposes of our demonstration we are going to build a simple mod file to allow us to easily switch between the different international stores that APF4 supports. Starting from a specimen modification file, we will make a decisions about where in the execution of the main script we will 'hook' into. We will access existing variables within the script and we will create a so called 'template variable', that is to say - a variable that will be available for displaying in our templates by surrounding the variable name with with double per-cent signs like so %%variable_name%% Download and the sample mod file specimen.mod and the final mod international.mod in one zip file # version: 1.040506 # copyright: Put your name here - # http://www.your-web-address-goes-here # license: GPL - # http://www.opensource.org/licenses/gpl-license.html # purpose: Example mod for APF # (Amazon Product Feeds - # by MrRat http://www.mrrat.com/) # description: A blank modification script - # with instructions for completion # # When you have created your Mod file put a # description of what your Mod file does here. # This line tells that main script which sub is being hooked into. # the format is %subs__name-of-modfile = ( name-of-original-sub => "Yes" ); %subs__specimen = ( original-sub => "Yes" ); # This line is the begining of the new sub you have created. # the format is: sub name-of-original-sub__name-of-modfile { sub original-sub__specimen { #put your code here; } # file must end with this 1; 1;# -- Script ends on line above this -- Now let's create a simple modfile using this specimen.As a simple example let's create a couple of links to the front page of stores other than the current locale. For example if our user is viewing products from Amazon.com we need to create links to Amazon.co.uk and Amazon.de We will wrap this little piece of HTML in a div statement to allow us to control the formatting fromm either a style block or a .css style sheet. We need a name for our modification file - 'international' seems as good as any other for our purposes. To begin with let's make a decision about which is the most suitable variable to store our final code: The %MY_variables is used to store HTML that will automatically be placed into our final page. We will add the key 'international_links' to $MY_variables. It will be accessible in our templates if we use Next we need to decide which of the subs within MrRat's script is the best place to hook into to carry out our task. To make this decision you may have to understand which parts of the script do what. There is no point in trying to generate HTML that incorporates values that have not yet been generated by the core program. Because this modification needs to know the current locale I felt that the best place to hook into was the initialize_locale sub, sounds logical. Now that we have made these decisions we are in a position to make the necessary edits to the script.
Our code is quite simple in this instance. We are going to add a few lines of HTML to $MY_variables{international_links} as we decided earlier. Because we are creating links in our html we will need to access the current script's name. We will successively add a link to each locale, but only if that locale is not the current locale - the one the user is already viewing. $MY_variables{international_links} .= "<div class="international_links">"; $MY_variables{international_links} .= " | <a href="$MY_variables{script_name}?locale="> UK Store</a>" unless $MY_variables{current_locale} eq 'uk'; $MY_variables{international_links} .= " | <a href="$MY_variables{script_name}?locale="> US / Worldwide Store</a>" unless $MY_variables{current_locale} eq 'us'; $MY_variables{international_links} .= " | <a href="$MY_variables{script_name}?locale="> Deutscher Shop</a>" unless $MY_variables{current_locale} eq 'de'; $MY_variables{international_links} .= " | ";</div> Following these steps should result in the following file: # -- international.mod starts on next line. # version: 1.040506 # copyright: Dean Marshall - # http://www.deanmarshall.co.uk # license: GPL - # http://www.opensource.org/licenses/gpl-license.html # purpose: Example mod for APF (Amazon Product Feeds - # by MrRat http://www.mrrat.com/ # description: Example of a modification script - # Creates a basic %%international_links%% # tag that when placed in your page template # allows you to switch to the front page of the # Amazon stores for the other locales [countries]. # # To control the appearance of the resultant # text use CSS class. international_links{} in # style block or .css style sheet # This line tells that main script which sub is being hooked into. %subs__international = ( initialize_locale => "Yes" ); # This is the main mod file script. # The name of the sub # is sub-being-hooked-into 2underscores name-of-mod-file sub initialize_locale__international { #my (define-some-variables-here); #put your code here; $MY_variables{international_links} .= "<div class="international_links">"; $MY_variables{international_links} .= " | <a href="$MY_variables{script_name}?locale=uk"> UK Store</a>" unless $MY_variables{current_locale} eq 'uk'; $MY_variables{international_links} .= " | <a href="$MY_variables{script_name}?locale=us"> US / Worldwide Store</a>" unless $MY_variables{current_locale} eq 'us'; $MY_variables{international_links} .= " | <a href="$MY_variables{script_name}?locale=de"> Deutscher Shop</a>" unless $MY_variables{current_locale} eq 'de'; $MY_variables{international_links} .= " | </div>"; } 1; Now we have our Mod file - what do we do with it?Proceed as per the normal instructions for using Mod files. |
Buy Amazon Products Feed Bridge Now
APF Bridge is available for purchase and download through our online store.
Buy APF Bridge and integrate MrRat's famous APF script into your site.



