Execution of arbitrary PHP code in frontend templates

When applying various adjustments to your design theme, you may find it necessary to embed the execution result of some arbitrary PHP code in your frontend. Since direct execution of PHP code in HTML templates is not allowed, you need to save such a PHP snippet as a custom helper method and call that method in your template. Creation and use of custom helpers are described in detail in the developer documentation →


Suppose you need to add some HTML block generated by a PHP snippet to an arbitrary location in your Shop-Script 5 storefront; e.g., to display currency exchange rates. To do so, define custom class shopCustom in file wa-apps/shop/lib/classes/shopCustom.class.php as shown below:


class shopCustom

    public static function getExchangeRatesHtml() //you may write any name for your method
    //use of public static identifier is mandatory
        ... //arbitrary PHP code generating the required HTML snippet to be displayed in frontend
        return $html; //value returned by method is added to the HTML code of the page to which you have added its name (see example below)
    public static function ...() //here comes another helper method; you may add an unlimited number of methods in this class


In order to add the currency exchange rates block (in this example) to your online storefront, call your custom helper method in the desired location of your template or info page source code as shown below:

Correct operation of your custom helper may require clearing of framework's cache in Installer.


    Add comment

    To add a comment please sign up or login