Migrate a classic template to a Blade template

Convert an old affiliate-toolkit template with %placeholders% into a Blade template: structure, skeleton and a mapping of the common placeholders.

Older affiliate-toolkit templates used placeholders such as %title% in three parts: header, body and footer. Current templates use the Blade template engine. Blade templates are faster – only the values you use are calculated – and more flexible, because you can use conditions and loops. This article shows how to convert a classic template.

Prerequisite: you know HTML and have a classic template you want to convert. If you would rather keep it, the Template Compatibility module renders classic templates as before.

An "Old template" (template compatibility) with header, body and footer using %placeholders% such as %title%, %saleprice% and %link%.
A classic template with header, body and footer and %placeholders%.

How the parts map

  • Header – everything before @foreach.
  • Body (repeated per product) – everything between @foreach ($products as $product) and @endforeach.
  • Footer – everything after @endforeach, usually the disclaimer.

Inside the loop, every placeholder becomes a call to $formatter with the current $product. Use {{ … }} for plain text (it is escaped) and {!! … !!} for values that contain HTML, such as links, images or lists.

Skeleton to start from

Create a new template under affiliate-toolkit → Templates and start with this skeleton. Then move your HTML from the classic body into the loop and replace the placeholders.

<div class="atkp-container {{ $parameters->get_css_container_class() }}">
    @if($products != null)
        @foreach ($products as $product)
            <div class="atkp-box {{ $parameters->get_css_element_class() }}">
                <a {!! $formatter->get_title_link($product) !!}>{{ $formatter->get_shorttitle($product) }}</a>
                {{ $formatter->get_pricetext($product, '%s', '') }}
                <a {!! $formatter->get_button_link($product) !!}>{!! $formatter->get_button_text($product) !!}</a>
            </div>
        @endforeach

        @if(count($products) > 0 && $parameters->get_show_disclaimer())
            <span class="atkp-disclaimer">{!! $formatter->get_disclaimer($products[0], $parameters->get_disclaimer_text()) !!}</span>
        @endif
    @endif
</div>

Conditions let you hide elements that have no value – something the classic engine could not do:

@if($formatter->get_listpricetext($product, '%s') != '')
    <span class="atkp-listprice">{{ $formatter->get_listpricetext($product, $translator->get_listprice()) }}</span>
@endif

Common placeholders

The table maps the most used classic placeholders to their Blade equivalent. Link placeholders return the attributes of an <a> tag, so write <a {!! … !!}> just as you wrote <a %link%> before.

ClassicBlade
%title%{{ $formatter->get_title($product) }}
%short_title%{{ $formatter->get_shorttitle($product) }}
%titlelink%{!! $formatter->get_title_link($product) !!}
%titlelinkmark%{!! $formatter->get_title_mark($product) !!}
%productlink%{!! $formatter->get_productlink($product) !!}
%producturl%{{ $formatter->get_producturl($product) }}
%link%{!! $formatter->get_button_link($product) !!}
%linktext%{!! $formatter->get_button_text($product) !!}
%linkmark%{!! $formatter->get_button_mark($product) !!}
%cartlink%{!! $formatter->get_cartlink($product) !!}
%detailurl%{{ $formatter->get_detailurl($product) }}
%price%{{ $formatter->get_pricetext($product, '%s', 'Price not available') }}
%listprice%{{ $formatter->get_listpricetext($product, '%s') }}
%listprice_text%{{ $formatter->get_listpricetext($product, $translator->get_listprice()) }}
%save_percentage%{{ $formatter->get_percentagesaved($product, '-%s%%') }}
%shipping%{{ $formatter->get_shipping($product, '%s', '') }}
%totalprice%{{ $formatter->get_total($product) }}
%info_text%{!! $formatter->get_infotext($product) !!}
%priceinfo_text%{!! $formatter->get_priceinfotext() !!}
%smallimage%{!! $formatter->get_smallimage($product) !!}
%mediumimage%{!! $formatter->get_mediumnimage($product) !!}
%mediumimageurl%{{ $formatter->get_mediumnimageurl($product) }}
%largeimageurl%{{ $formatter->get_largeimageurl($product) }}
%star_rating%{!! $formatter->get_star_rating($product) !!}
%rating%{!! $formatter->get_rating_text($product) !!}
%reviewslink%{!! $formatter->get_reviewslink($product) !!}
%features_text%{!! $formatter->get_featuretext($product) !!}
%description_text%{!! $formatter->get_descriptiontext($product) !!}
%pro%{!! $formatter->get_proslist($product) !!}
%contra%{!! $formatter->get_contralist($product) !!}
%testresult%{!! $formatter->get_testresult($product) !!}
%prime_icon%{!! $formatter->get_primelogo($product) !!}
%by_text%{!! $formatter->get_bytext($product) !!}
%predicate_text%{!! $formatter->get_predicate_text($product) !!}
%predicate_id%{{ $formatter->get_predicate_id($product) }}
%bestseller_number%{{ $formatter->get_bestseller_number($product->item_idx) }}
%bestseller_text%{!! $formatter->get_bestseller_text($product->item_idx) !!}
%shoplogo%{!! $formatter->get_shop_logo($formatter->get_shop_value($product)) !!}
%refresh_date%{{ $formatter->get_refreshdate($product) }}
%refresh_time%{{ $formatter->get_refreshtime($product) }}
%disclaimer%{!! $formatter->get_disclaimer($product) !!}

The template editor shows all available placeholders in its toolbar; the complete list is in Placeholders for Blade templates.