emailsmartysmarty3shopware

Check whether a string contains substring with Smarty


I'm having a bit of a problem with my email-templates. Shopware for some reason uses Smarty as a template language for their emails. My Problem now is that I have this email-template


Tracking: 

  {if $sDispatch.name == "DHL national" }
      https://sampleurl.com={$sOrder.trackingcode}
  {else if $sDispatch.name == "DPD"}
      https://sampleurl.com={$sOrder.trackingcode}
  {else if $Dispatch.name == "Deutsche Post"}
      http://sampleurl.com
  {else}
      Your order can not be tracked.
  {/if}

And there are many dispatch options for the parcels (small parcel, with insurance ...). Now I want to check whether the String in $sDispatch.name includes "DHL", "DPD" or "Deutsche Post" to determine which tracking link should be sent to the customer.

I could not find a reasonable solution to check if a String contains these pieces of given substrings. Does anyone have a neat little solution that will do the trick? Anything is appreciated! :-)


Solution

  • You can use the modifier |strstr to search for a certain string in a string.

    https://www.php.net/manual/de/function.strstr.php

    Example:

    {if $sDispatch.name|strstr:"DHL"}This is a dispatch that contains the string DHL{/if}