Search code examples
phpopencart

Remove Spaces between image names


I have an Attribute.text name "Cushion Modified" and i am passing the same dynamically

{% if attribute.name=="Shape" %} {% set image = 'image/catalog/Products/shapes/sample/' ~ attribute.text ~ '.png' %} {% endif %}

After executing it the image src looks like src="image/catalog/Products/shapes/sample/Cushion" modified.png=""

I want to make it like image/catalog/Products/shapes/sample/Cushionmodified.png

Any help


Solution

  • I was reading and you would need to create your own Twig extension to do this, so the previous suggestion is not possible to implement, however, inside your extension you should be able to run that PHP code.

    You can also refer to where they explain you would need an extension for this :

    Call PHP function from Twig template

    Is there any way to write PHP code inside .twig file in WordPress? I am trying to send a mail by using the form values from a .twig template file

    For reference, the PHP code to remove spaces from a string :

    str_replace(' ','',$string_var_containing_spaces)