2017-02-20 3 views
0

J'ai un modèle Smarty qui est en train d'insérer une image du produit. Ce que je voudrais faire, c'est modifier ce code pour qu'il ne me donne que le src de l'image.Obtenir img src avec le modèle Smarty

Le modèle comprend le fichier « product_icon.tpl » et de ce que je crois que c'est le code correspondant de ce fichier:

{capture name="main_icon"} 
    <a href="{"$product_detail_view_url"|fn_url}"> 
     {include file="common/image.tpl" obj_id=$obj_id_prefix images=$product.main_pair image_width=$settings.Thumbnails.product_lists_thumbnail_width image_height=$settings.Thumbnails.product_lists_thumbnail_height} 
    </a> 
{/capture} 

Ensuite, le fichier « image.tpl » qu'il y avait inclus contient ce (parés à une partie pertinente pour la brièveté):

{capture name="product_image_object"} 
{** Sets image displayed in product list **} 
{hook name="products:product_image_object"} 
    <img class="ty-pict {$valign} {$class} {if $lazy_load}lazyOwl{/if} {if $generate_image}ty-spinner{/if} cm-image" {if $obj_id && !$no_ids}id="det_img_{$obj_id}"{/if} {if $generate_image}data-ca-image-path="{$image_data.image_path}"{/if} {if $lazy_load}data-{/if}src="{if $generate_image}{$images_dir}/icons/spacer.gif{else}{$image_data.image_path}{/if}" alt="{$image_data.alt}" title="{$image_data.alt}" {if $image_onclick}onclick="{$image_onclick}"{/if} {if $image_width || $image_height} style="min-width: {$image_data.width}px; min-height: {$image_data.height}px; "{/if}/> 
    {if $image_data.alt}<span class="stonestreets-caption">{$image_data.alt}</span>{/if} 
{/hook} 
{/capture} 

peuvent être combinés et simplifié ces extraits de code vers le bas que la première sortie src de l'image redimensionnée?

Répondre

1

Vous pouvez toujours utiliser prin_r en tpl pour vérifier les variables

{$product.main_pair|print_r} 

seront affichés quelque chose de similaire avec des chemins différents

Array 
(
    [pair_id] => 1072 
    [image_id] => 0 
    [detailed_id] => 1285 
    [position] => 0 
    [detailed] => Array 
     (
      [object_id] => 247 
      [object_type] => product 
      [image_path] => http://localhost/cs-cart-git-dev/images/detailed/1/nokia_n1_perspectives_-_app.jpg 
      [alt] => 
      [image_x] => 5000 
      [image_y] => 3096 
      [http_image_path] => http://localhost/cs-cart-git-dev/images/detailed/1/nokia_n1_perspectives_-_app.jpg 
      [https_image_path] => https://localhost/cs-cart-git-dev/images/detailed/1/nokia_n1_perspectives_-_app.jpg 
      [absolute_path] => /Applications/MAMP/htdocs/cs-cart-git-dev/images/detailed/1/nokia_n1_perspectives_-_app.jpg 
      [relative_path] => detailed/1/nokia_n1_perspectives_-_app.jpg 
     ) 
) 

maintenant sont plus faciles à repérer ce dont vous avez besoin

<img src="{$product.main_pair.detailed.image_path}" width="{$product.main_pair.detailed.image_x}" height="{$product.main_pair.detailed.image_y}" alt="{$product.main_pair.detailed.alt}" /> 

Pour redimensionner l'image e à la volée s'il vous plaît utiliser

{$image_data=$product.main_pair|fn_image_to_display:$image_width:$image_height} 
<img src="{$image_data.detailed.image_path}" width="{$image_data.detailed.image_x}" height="{$image_data.detailed.image_y}" alt="{$image_data.detailed.alt}" /> 
+0

C'est vraiment pratique merci. Mais cela me donne la taille d'origine. Comment puis-je trouver le chemin de l'image redimensionnée? – user500665

+0

Désolé, ça ne me donne rien? – user500665

+0

Avez-vous changé $ image_width: $ image_height avec vos propres valeurs? – Hungryweb