I have a link that came from a Scrapper in a .php file.
I'd like to include that link into a in a .html.twig file
I tried $url and $amazon and $asin but I don't think the structure works.
Basically, this site scraps amazon URLs and identifies the ASIN ID.
There is a ProductController.php file
namespace App\Controller;
use App\Entity\Product; use App\Form\AddProductType; use App\Form\ProductType; use App\Repository\ProductRepository; use App\Service\AmazonScrapper; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use > App\Service\LookingForAsin;
/** * @Route("admin/product") */ class ProductController extends Controller {
/** * @Route("/new", name="product_indexAjax", methods="GET|POST") * @param Request $request *** @param LookingForAsin $lookingForAsin * @param AmazonScrapper $amazon** * @param ProductRepository $productRepository * @return JsonResponse */ public function new(Request $request, LookingForAsin $lookingForAsin, AmazonScrapper $amazon, ProductRepository
$productRepository) { $product = new Product(); $error = '';
$content = json_decode($request->getContent(), true); **$asin = $lookingForAsin->extractAsin($content['asin']); if (empty($asin)) {** return new JsonResponse( ['error' => 'Oops, you must enter the url of a product.'] ); } else if (!empty($productRepository->findBy(['asin' => $asin]))) { return new JsonResponse( ['error' => 'Oops, the product already exists.'] ); } $amazon->init($content['asin']); $product->setAsin($asin); $product->setTitle($amazon->getTitle()); $product->setPicture($amazon->getPicture()); $product->setPrice($amazon->getPrice()); $product->setRating($amazon->getRating()); $product->setRatingReview1Star($amazon->getReviewRating(1)); ```` $product->setDescription($amazon->getDescription()); $em = $this->getDoctrine()->getManager(); $em->persist($product); $em->flush(); if($product->getPrice() == 0) { $error = 'Oops, this product is probably unavailable :/'; } return new JsonResponse( [ 'template' => $this->renderView('admin/product/item.html.twig', [ 'product' => $product, ] ), 'error' => $error, ] ); } /** * @Route("/", name="product_index", methods="GET|POST") * @param Request $request * @param ProductRepository $productRepository * @return Response */ public function index(Request $request, ProductRepository $productRepository) { $product = new Product(); $form = $this->createForm(AddProductType::class, $product); $form->handleRequest($request); return $this->render('admin/product/index.html.twig', [ 'products' => $productRepository->findBy([], ['id' => 'DESC']), 'product' => $product, 'form' => $form->createView() ] ); } /** * @Route("/{id}", name="product_show", methods="GET|POST") * @param Request $request * @param int $id * @return Response */ public function show(Request $request, int $id): Response { $em = $this->getDoctrine()->getManager(); $product = $em->getRepository(Product::class)->find($id); $form = $this->createForm(ProductType::class, $product); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em->flush(); return $this->redirectToRoute('product_show', ['id' => $product->getID()]); } return $this->render('admin/product/show.html.twig', [ 'product' => $product, 'form' => $form->createView(), ] ); } /** * @Route("/{id}/edit", name="product_edit", methods="GET|POST") * @param Request $request * @param Product $product * @return Response */ public function edit(Request $request, Product $product): Response { if ($request->request->all()['name'] == "title") { $product->setTitle($request->request->all()['value']); } else if ($request->request->all()['name'] == "picture") { $product->setPicture($request->request->all()['value']); } else if ($request->request->all()['name'] == "description") { $product->setDescription($request->request->all()['value']); } $em = $this->getDoctrine()->getManager(); $em->persist($product); $em->flush(); return new JsonResponse( [ 'picture' => $product->getPicture(), ] ); } ``
`
Then, this is the .html.twig file
{% extends 'base.html.twig' %}
{% block title %}Wishlist{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('build/index.css') }}">
{% endblock %}
{% block body %}
<div class="header">
<img class="logo text-center" src="{{ asset('build/images/logo.png') }}" height="70px">
<h1>No idea what to get? Check your friend's wishlist here!</h1>
<div class="form-container">
{{ form_start(form, {'attr': {'class': 'form-row'}}) }}
<div class="col mb-3">
{{ form_widget(form.mail, {'attr': {'class': 'email-input'}}) }}
</div>
<button type="submit" class="btn btn-danger"> OK </button>
{{ form_end(form) }}
</div>
</div>
** THIS IS WHERE I WANT TO ADD THE URL ***
<a href="{{ asset('$url') }} > (# link to Amazon page #)
<div class="container wishlist">
{% if user.productUsers is defined %}
{% for products in user.productUsers %}
{% set product = products.product %}
<div class="row product-card">
<div class="product-container-img">
<img src="{{ product.picture }}" alt="">
</div>
<div class="product-container-content">
<div class="product-container-header">
<div class="product-container-title">
<h2>{{ product.title }}</h2>
</div>
<div class="product-container-rating">
{{ include('admin/product/rating.html.twig') }}
</div>
</div>
<div><p>{{ product.description|raw }}</p></div>
<div class="price">{{ product.price }} €</div>
</div>
</div>
{% endfor %}
{% else %}
{% set flashes = app.flashes('notice') %}
{% if flashes|length == 0 %}
<div class="arrow-container">
<i class="fas fa-arrow-circle-up arrow"></i>
</div>
{% else %}
{% for message in flashes %}
<div class="flash-notice">
{{ message }}
</div>
{% endfor %}
{% endif %}
{% endif %}
</div>
</a>
{% endblock %}
I would like to be able to click on that div part and be directed to the product URL
Thank you!