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
Always keep the specimen.mod file safe - it will form the basis of any future mod files your create. Then work through the steps outlined below to create the file international.mod

# 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
%%international_links%%

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.

  • 1. Make a copy of specimen.mod called international.mod
  • 2. Okay - to begin, lets write the notes at the top of the script.
  • 3. Now work through the specimen file and replace the words 'name-of-modfile' with the actual name of our new modfile in this case 'international'
  • 4. Now we replace all instances of 'original-sub' with the name of the sub in MrRat's script that we wish to hook into.

    In this instance we chose to hook into 'initialize_locale'.

  • 5. Put your new code under the line: #put your code here;

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.
This is done with $MY_variables{script_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;
# -- international.mod ends on above line.

Now we have our Mod file - what do we do with it?

Proceed as per the normal instructions for using Mod files.
1. Place the mod file in your mod-files directory.
2. Run the apf_config script.
3. Enable the mod in the config screen.
4. Save your settings.
5. Place any necessary %%template_variables%% in your page, products, item, or other templates.
6. Run your APF script as normal and watch out for the appearance of your newly created features.

 

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.

Buy Now!
Only UK Pound 10.00

Web designer Lancaster and Morecambe PHP Amazon store script Pipex Internet Pipex broadband review Pipex criminal fraud Bulletproof Themes Bulletproof Themes UK Dean Marshall Mambo and Joomla Consultant | Joomla and Mambo consultants Joomla Amazon Component British English crossword and anagram solver British English crossword and anagram solver Professional Researcher Professional Researcher
The JoomlaSphere | The JoomlaSphere | The JoomlaSphere | The JoomlaSphere JoomlaMonkey | JoomlaMonkey | UK Joomla Consultancy Services Joomla Consultancy Services UK Joomla Consultancy Services Joomla Consultancy Services
Buy gifts for women UK Buy gifts for men UK find gifts for men UK Buy gifts for women UK Buy gadgets Buy gifts for gays UK Buy gifts for gays UK Buy toys in the UK
The Mambo Foundation Mambo Tracker Mambo Foundation Membership Mambo Foundation Home Download The Source Forum Donate Newsroom Mambo Love Mambo Documentation Alternative documentation Software Forge Bug Tracker SVN Instructions Mambo on the Forge Joint Commercial Developers Extensions for Joomla and Mambo Amazon Products Feed Bridge Joomla Amazon Components - Amazon Products Feed Bridge Million Dollar Pet Pix - Make your pet a star