Placeholders for Blade templates

All variables and formatter methods for affiliate-toolkit Blade templates: product, offer, image, shop, translator and parameter placeholders, examples.

Product templates in affiliate-toolkit use the Blade template engine (BladeOne). Instead of fixed %placeholders% you call small methods on helper objects, for example {{ $formatter->get_title($product) }}. This page lists every variable and method you can use, built from the plugin source.

The toolbar above the template editor inserts most of them for you. Use {{ … }} for plain text (it is HTML-escaped) and {!! … !!} for values that contain HTML, such as images, links attributes or lists.

Template editor with Blade markup, a @foreach loop over $products, the placeholder toolbar above the editor and the CSS field
The toolbar inserts containers, loops and placeholders.

Variables in every template

VariableContent
$productsArray of the products to render (one product for [atkp_product], several for lists). Loop over it with @foreach.
$productThe current product inside @foreach ($products as $product). $product->item_idx holds its position (1, 2, 3 …).
$formatterFormats product, offer, image and shop data. Almost every placeholder below is a method of this object.
$translatorReturns translated standard texts such as "Price: %s" (see the table below).
$parametersAll options from the shortcode, the template settings and the display settings (show price, show rating, CSS classes …).
$shopThe shop of the first product (or the first shop when shops are rendered).
$shopsArray of shops; only filled when a template renders shops instead of products (for example the shop selection of the product search).

Inside expressions you can also use normal PHP functions such as number_format() or date(). For security, affiliate-toolkit removes <?php … ?> tags, @php … @endphp blocks and @inject from templates you create in the backend.

The three loops

Every placeholder needs its object. Product placeholders need $product, so they must be inside the product loop. Offer placeholders need $offer and image placeholders need $image, so they go into a nested loop. The "Loops" menu of the toolbar inserts these blocks.

Product loop ($product)

<!--header-->
@foreach ($products as $product)
    <!--product content-->
    {{ $formatter->get_title($product) }}
@endforeach
<!--footer-->

Offer loop ($offer)

@foreach ($products as $product)
    {{ $formatter->get_title($product) }}

    @foreach ($formatter->get_offers($product, true) as $offer)
        <!-- offer content -->
        {!! $formatter->get_shop_logo($offer->shop) !!}
        {{ $formatter->get_offer_price($offer, $translator->get_price()) }}
        <a {!! $formatter->get_offer_productlink($offer) !!}>{{ $formatter->get_offer_linktext() }}</a>
    @endforeach
@endforeach

Image loop ($image)

@foreach ($products as $product)
    {{ $formatter->get_title($product) }}

    @foreach ($formatter->get_images($product, true) as $image)
        <!-- image content -->
        {!! $formatter->get_image_mediumimage($product, $image) !!}
    @endforeach
@endforeach

Product: texts and labels

PlaceholderOutput
$formatter->get_title($product)Product title (or the WooCommerce title if the title link points to WooCommerce).
$formatter->get_shorttitle($product)Title shortened to the "short title" length from the settings.
$formatter->get_bytext($product)"by Author" or "by Manufacturer", empty if neither is set.
$formatter->get_listtitle($product)Title of the list the product comes from.
$formatter->get_postlist($product)HTML list (ul.atkp_postlist) of the posts where the product is the main product.
$formatter->get_featuretext($product)Features as HTML.
$formatter->get_featuretext_short($product)Features as a bullet list, limited to the feature count of the template.
$formatter->get_descriptiontext($product)Description as HTML.
$formatter->get_descriptiontext_short($product)Description without HTML, cut to the description length of the template.
$formatter->get_infotext($product)Features or short description, depending on the "box content" option.
$formatter->get_proslist($product)Pro arguments as ul.atkp-pro. Optional 2nd parameter: mask such as '<b>%s</b>'.
$formatter->get_contralist($product)Contra arguments as ul.atkp-contra, same mask parameter.
$formatter->get_testresult($product)Test badge with rating, verdict and date.
$formatter->get_predicate_text($product)Text of the highlight label (for example "Best price"), empty if none.
$formatter->get_predicate_id($product)Number of the highlight (1, 2, 3 …), useful for CSS classes.
$formatter->get_predicate_color($product)Colour of the highlight.
$formatter->get_predicate_borderstyle($product)Inline style border-color:… for the highlight.
$formatter->get_bestseller_text($product->item_idx)"#1 Best Seller" etc. (respects the bestseller ribbon setting).
$formatter->get_bestseller_number($product->item_idx)"#1", "#2" …
$formatter->get_variationname($product)Names of the variation attributes, separated by ", ".
$formatter->get_primelogo($product)Prime logo (linked if enabled), only for Prime products.
$formatter->get_warehouselogo($product)"Warehouse" label for Amazon Warehouse offers.

Product: prices, dates and disclaimer

Price methods take an optional sprintf mask. Pass a translator text to get a label, for example $formatter->get_pricetext($product, $translator->get_price(), $translator->get_pricenotavailable()) outputs "Price: 19.99 €" or "Price not available".

PlaceholderOutput
$formatter->get_pricetext($product, $format, $empty)Sale price, formatted with the currency of the shop. $format is a sprintf mask (default '%s'), $empty is shown if there is no price.
$formatter->get_listpricetext($product, $format, $empty)List price; empty if it is not higher than the sale price.
$formatter->get_savetext($product, $format)Amount saved.
$formatter->get_percentagesaved($product, $format)Percentage saved, default mask '-%s%%'.
$formatter->get_basepricetext($product, $format)Base price per unit, default mask '(%s / %s)'.
$formatter->get_shipping($product, $format, $empty)Shipping costs.
$formatter->get_total($product, $format, $empty)Price plus shipping.
$formatter->get_priceinfotext()"Price incl. VAT., Excl. Shipping".
$formatter->get_refreshdate($product)Date of the last product update.
$formatter->get_refreshtime($product)Time of the last product update.
$formatter->get_disclaimer($product, $text)Disclaimer with %refresh_date% and %refresh_time% replaced. Without $text the text from the settings is used. Returns nothing inside templates included with @include, so the disclaimer appears only once.

Product: images, ratings, offers and custom fields

PlaceholderOutput
$formatter->get_smallimageurl($product)URL of the small main image (placeholder image if none).
$formatter->get_mediumnimageurl($product)URL of the medium main image. Note the spelling with "n".
$formatter->get_largeimageurl($product)URL of the large main image.
$formatter->get_smallimage($product)Complete <img> tag, small.
$formatter->get_mediumnimage($product)Complete <img> tag, medium (spelling with "n").
$formatter->get_largeimage($product)Complete <img> tag, large.
$formatter->get_star_rating($product)Star rating as HTML (span.atkp-star).
$formatter->get_rating_text($product)"4.5 of 5 stars".
$formatter->get_reviewstext($product)"123 customer reviews" (or "Show customer reviews").
$formatter->get_wp_review_rating($product)Total rating of the WP Review plugin, if installed.
$formatter->get_images($product, true, 0)Array of $image objects for the image loop. 2nd parameter: include the main image, 3rd: maximum number (0 = all).
$formatter->get_offers($product, true, 0)Array of $offer objects for the offer loop, sorted by price. 2nd parameter: include the main offer, 3rd: maximum number (0 = template setting).
$formatter->get_minoffer($product)Cheapest offer (an $offer object).
$formatter->get_maxoffer($product)Most expensive offer.
$formatter->get_offercount($offers)"3 offers" for an array of offers.
$formatter->get_displayfield($product, 'customfield_name')Value of a custom field or taxonomy, formatted with prefix and suffix. Prefixes: customfield_ (global field), cf_ (field group), customtaxonomy_ (custom taxonomy), ct_ (taxonomy field of a field group).
$formatter->get_shop_value($product)The shop object of the product, for the shop methods below.

Fields created with ACF (Advanced Custom Fields) are read with the ACF function, for example {{ get_field('my_field', $product->productid) }}. The toolbar lists them under "ACF fields" when ACF is active.

Shop

Shop methods need a shop object: $formatter->get_shop_value($product) in the product loop or $offer->shop in the offer loop.

PlaceholderOutput
$formatter->get_shop_title($shop)Shop name.
$formatter->get_shop_logo($shop)<img> tag of the shop logo (shop name if no logo is set or logos are disabled).
$formatter->get_shop_smalllogo($shop)<img> tag of the small logo.
$formatter->get_shop_logourl($shop)URL of the shop logo.
$formatter->get_shop_smalllogourl($shop)URL of the small shop logo.
$formatter->get_shop_value($product)->customfield1Custom field 1 of the shop (also customfield2, customfield3).

Object $offer

Use these inside @foreach ($formatter->get_offers($product, true) as $offer).

PlaceholderOutput
$formatter->get_offer_title($offer)Title of the offer.
$formatter->get_offer_price($offer, $format, $empty)Price of the offer.
$formatter->get_offer_oldprice($offer, $format, $empty)List price of the product the offer belongs to.
$formatter->get_offer_shipping($offer, $format, $empty)Shipping costs of the offer.
$formatter->get_offer_total($offer, $format, $empty)Price plus shipping.
$formatter->get_offer_availability($offer)"Availability: …" (N/A if unknown). Optional 2nd parameter: own mask.
$formatter->get_offer_url($offer)Affiliate URL of the offer.
$formatter->get_offer_productlink($offer)Link attributes for the offer (href, rel, target, title).
$formatter->get_offer_linktext()"Buy now".
$formatter->get_offer_bestprice($offer, $product)"Best price" if this is the cheapest offer, otherwise empty.
$formatter->get_shop_logo($offer->shop)All shop methods from the table above, with $offer->shop as parameter.
$offer->shop->customfield1Custom field 1 of the offer's shop (also 2 and 3).

Object $image

Use these inside @foreach ($formatter->get_images($product, true) as $image). Missing sizes fall back to the other sizes of the main image.

PlaceholderOutput
$formatter->get_image_smallimageurl($product, $image)URL of the small version.
$formatter->get_image_mediumimageurl($product, $image)URL of the medium version.
$formatter->get_image_largeimageurl($product, $image)URL of the large version.
$formatter->get_image_smallimage($product, $image)<img> tag, small.
$formatter->get_image_mediumimage($product, $image)<img> tag, medium.
$formatter->get_image_largeimage($product, $image)<img> tag, large.

Translated texts ($translator)

These methods return the standard texts in the language of your WordPress site. Many of them contain %s and are meant as masks for the price methods.

MethodText (English)
$translator->get_price()"Price: %s" (mask for get_pricetext)
$translator->get_listprice()"List Price: %s"
$translator->get_yousave()"You Save: %s"
$translator->get_shipping()"Shipping: %s"
$translator->get_shippingna()"Shipping: N/A"
$translator->get_pricenotavailable()"Price not available"
$translator->get_price_simple()"Price"
$translator->get_pricedouble()"Price:"
$translator->get_insteadof()"instead of:"
$translator->get_val()"%s" (plain mask)
$translator->get_buynow()"Buy now"
$translator->get_productunavailabletext()"This product is currently unavailable."
$translator->get_manufacturer()"Manufacturer"
$translator->get_sortby() / get_search() / get_searchproduct() / get_searching() / get_searchterm() / get_noproducts()Texts for search forms and search results
$translator->get_searchresultsat($name)"Search results at …"
$translator->get_compareproducts() / get_product1() … get_product4()Texts for product comparisons
$translator->get_monthlypricehistorytitle() / get_lastxdayspricehistorytitle($days)Headings for the price history

Options ($parameters)

The system templates check these options so that the settings and shortcode attributes keep working. Use them in your own templates with @if.

MethodReturns true / the value for
$parameters->get_showprice()Show the price.
$parameters->get_showlistprice()Show the list price.
$parameters->get_showpricediscount()Show the saving.
$parameters->get_showbaseprice()Show the base price.
$parameters->get_showstarrating() / get_hideemptystars()Show stars / hide stars without rating.
$parameters->get_showrating() / get_hideemptyrating() / get_linkrating()Show, hide when empty and link the review count.
$parameters->get_linkimage()Link the product image.
$parameters->get_showshopname()Show the shop logo or name.
$parameters->get_hideprocontra()Hide pro and contra lists.
$parameters->get_show_moreoffers() / get_moreoffers_template()Show more offers and the template to use for them.
$parameters->get_show_priceinfo() / get_priceinfo_text()Show the price notice and its text.
$parameters->get_show_disclaimer() / get_disclaimer_text()Show the disclaimer and its text.
$parameters->get_css_container_class() / get_css_element_class()CSS classes from the shortcode attributes containercss and elementcss.
$parameters->get_content()Content of the shortcode.

Complete example

A small product box with image, linked title, stars, price and button. It respects the price option and the button setting.

<div class="my-box {{ $parameters->get_css_container_class() }}">
@foreach ($products as $product)
    <img src="{{ $formatter->get_mediumnimageurl($product) }}" alt="{{ $formatter->get_title($product) }}">
    <a {!! $formatter->get_title_link($product) !!}>{{ $formatter->get_shorttitle($product) }}{!! $formatter->get_title_mark($product) !!}</a>
    {!! $formatter->get_star_rating($product) !!}
    @if ($parameters->get_showprice())
        <span class="price">{{ $formatter->get_pricetext($product, $translator->get_price(), $translator->get_pricenotavailable()) }}</span>
    @endif
    @if ($formatter->is_button_link_available($product))
        <a {!! $formatter->get_button_link($product) !!} class="atkp-button">{!! $formatter->get_button_text($product) !!}{!! $formatter->get_button_mark($product) !!}</a>
    @endif
@endforeach
</div>

Troubleshooting

  • Error "Call to undefined method … get_mediumimage": the toolbar entry "Medium image" in the product fields inserts get_mediumimage($product), but the method is called get_mediumnimage($product) (with "n"). The same applies to get_mediumnimageurl.
  • Undefined variable $product: the placeholder is outside the @foreach loop. Move it inside.
  • HTML is shown as text: use {!! … !!} instead of {{ … }}.
  • Enable the error display in the settings while you build a template. Rendering errors are also written to the affiliate-toolkit log.