Get Smarty

Donate

Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Advertisement

{html_image}

{html_image}用于生成HTML的<img>标签的 自定义函数。 如果没有提供heightwidth参数, 此函数会自动从图片文件计算出来。

参数名称 类型 必选参数 默认值 说明
file string Yes n/a 图片名称/路径
height string No 真实图片高度 图片显示高度
width string No 真实图片宽度 图片显示宽度
basedir string no 网站根目录 相对路径的起始目录
alt string no 图片的说明内容
href string no n/a 图片上的链接地址
path_prefix string no n/a 显示路径的前缀
  • basedir设置了相对图片路径的起始目录。如果没有提供, 则使用网站根目录$_ENV['DOCUMENT_ROOT']。 如果开启了安全限制,图片文件必须放置在$secure_dir目录。 参见安全机制来了解更多。

  • href设置图片上超链接地址。如果链接地址有提供,那么 图片标签的外围会加上<a href="超链接地址"><a>的标签。

  • path_prefix可选的,设置显示路径时的前缀字符串。 当你需要给图片设置不同的服务器名时,这会很有用。

  • 其他不在上面列表中的键值对参数,会直接在输出的<img>标签中显示成 名称=值 的属性。

技术说明

{html_image}需要每次都读取硬盘上的图片,并且计算图片长宽。 除非你开启了缓存,否则一般建议是避免使用 {html_image},用回HTML的IMG标签,会有更高的性能。

Example 8.8. {html_image} 例子


{html_image file='pumpkin.jpg'}
{html_image file='/path/from/docroot/pumpkin.jpg'}
{html_image file='../path/relative/to/currdir/pumpkin.jpg'}

  

输出:


<img src="pumpkin.jpg" alt="" width="44" height="68" />
<img src="/path/from/docroot/pumpkin.jpg" alt="" width="44" height="68" />
<img src="../path/relative/to/currdir/pumpkin.jpg" alt="" width="44" height="68" />

  

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors