Reputation: 366
Im working in a project using symfony, and I've a view in which i've to display an image of an entity, i used the same method of the upload recommanded by the documentation, the upload is working fine, but the problem I faced when I want to display the image, I get an exception as following :
A hash key must be followed by a colon (:). Unexpected token "punctuation" of value "." ("punctuation" expected with value ":") in StockStockBundle:Payantfournisseur:imprime.html.twig at line 135
There is the code that gives me this exception : In the controller side :
$em = $this->getDoctrine()->getManager();
$entity = new Payantfournisseur();
$entity = $em->getRepository('StockStockBundle:Payantfournisseur')->find($id);
$user = $this->get('security.context')->getToken()->getUser();
$societe = new \User\UserBundle\Entity\Societe();
$societe = $em->getRepository('UserUserBundle:Societe')->find(2);
//$societe = $user->getSociete();
$facture = $entity->getIdfacturefournisseur();
$fournisseur = $facture->getIdfournisseur();
$articles = $em->getRepository('StockStockBundle:Lignefacturefournisseur')
->getArtFromLines($facture);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Devis entity.');
}
$deleteForm = $this->createDeleteForm($id);
return $this->render('StockStockBundle:Payantfournisseur:imprime.html.twig', array(
'entity' => $entity,
'fournisseur' => $fournisseur,
'facture' => $facture,
'articles' => $articles,
'delete_form' => $deleteForm->createView(),
'societe' => $societe,
// 'ayoub'=>'yes ayoub',
));
In the view side :
<img src="{{ asset({societe.pjs.getWebPath}) }}" alt="{{ societe.pjs.alt }}" class="spaced img-responsive" />
to give more explaination, pjs is a oneToOne related entity with the societe, pjs is the entity responsible for the uploaded files.
If someone has an idea, plz it could be very helpful thanks in advance!!!!!!!
Upvotes: 0
Views: 750
Reputation: 26
I found parsing error in twig
Remove brace from asset function, use variable like here:
<img src="{{ asset(societe.pjs.getWebPath) }}" alt="{{ societe.pjs.alt }}" class="spaced img-responsive" />
Upvotes: 1