Solution 1 :

You can try:

  {% set google_image = new get_google_image_class %}
  {% $google_image.destination = '.' %}
  {% $google_image.limit = 1 %}
  {% $google_image.display = true %}
  {% $google_image.GetImage($manufacturer) %}
  
  <p>Retrieved images: {{ $google_image.retrieved }} </p>

But I think you should write code PHP in file Controller. And using:

<p>Retrieved images: {{ $google_image.retrieved }} </p>

Problem :

I need to run a google images scraper depending on one of the twig variables. How can i execute the following code inside my .twig file.

      {$google_image = new get_google_image_class;
        $google_image->destination = '.'; // directory to save thse images
        $google_image->limit = 1; // limit the number of images, 0 for random
        $google_image->display = true; // output images to the page
        $google_image->GetImage($manufacturer);
        echo '<p>Retrieved images: '.$google_image->retrieved.'</p>';

        }

I need to run it with the following variable {{ manufacturer }} :

        <img alt="{{ manufacturer }}" src= "www.antonio.ecommercefull.com/catalog/controller/product/{{ manufacturer }}-1.jpg">

Comments

Comment posted by DarkBee

There is no need to run PHP inside a twig template, you fetch the image in your controller and then pass the URI as a variable towards the template

By