Php 使用Smarty模板获取img src
我有一个Smarty模板,当前正在插入产品图像。我想做的是修改代码,使其只提供图像的src 该模板包括文件“product_icon.tpl”,根据我收集的信息,这是该文件中的相关代码:Php 使用Smarty模板获取img src,php,smarty,cs-cart,Php,Smarty,Cs Cart,我有一个Smarty模板,当前正在插入产品图像。我想做的是修改代码,使其只提供图像的src 该模板包括文件“product_icon.tpl”,根据我收集的信息,这是该文件中的相关代码: {capture name="main_icon"} <a href="{"$product_detail_view_url"|fn_url}"> {include file="common/image.tpl" obj_id=$obj_id_prefix images=$p
{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}
{capture name=“main_icon”}
{/capture}
然后,包含在其中的“image.tpl”文件包含以下内容(为简洁起见,已修剪为相关部分):
{capture name=“product\u image\u object”}
{**设置产品列表中显示的图像**}
{hook name=“products:product\u image\u object”}
{if$image\u data.alt}{$image\u data.alt}{/if}
{/hook}
{/capture}
这些代码片段是否可以组合并简化为只输出大小调整后的图像的src?您始终可以在tpl中使用prin\u r来检查变量
{$product.main_pair|print_r}
将显示具有不同路径的类似内容
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
)
)
现在你更容易发现你需要什么
<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}" />
要动态调整图像大小,请使用
{$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}" />
{$image_data=$product.main_pair | fn_image_to_display:$image_width:$image_height}
非常方便,谢谢。但这是我原来的尺寸。我如何计算到调整大小的图像的路径?抱歉,这没有给我任何信息?您是否用自己的值更改了$image\u width:$image\u height?是的,通过设置变量,例如{$image\u width=500}
并直接用数字替换。
{$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}" />