-1

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

Rouf Wani
  • 21
  • 1
  • 7
  • The code you have shown is not PHP, but some templating language (Twig?) so you might want to [edit] the question tags so people with the right knowledge can find your question. – IMSoP Oct 03 '21 at 21:32

2 Answers2

1

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)
Telmo Dias
  • 3,938
  • 2
  • 36
  • 48
0

trim() function do it

go there https://www.w3schools.com/php/func_date_time.asp

paliz
  • 347
  • 2
  • 5