Smarty Manual
Prev | Chapter 8. Custom Functions | Next

# html_image

Attribute Name | Type | Required | Default | Description
--- | --- | --- | --- | ---
file | string | Yes | n/a | name/path to image
border | string | No | 0 | size of border around image
height | string | No | actual image height | height to display image
width | string | No | actual image width | width to display image
basedir | string | no | web server doc root | directory to base relative paths from
alt | string | no | "" | alternative description of the image
href | string | no | n/a | href value to link the image to

html_image is a custom function that generates an HTML tag for an image. The height and width are automatically calculated from the image file if none are supplied.

basedir is the base directory that relative image paths are based from. If not given, the web server document root (env variable DOCUMENT_ROOT) is used as the base. If security is enabled, the path to the image must be within a secure directory.

`href` is the href value to link the image to. If link is supplied, an <a href="LINKVALUE"><a> tag is put around the image tag.

All parameters that are not in the list above are printed as name/value-pairs inside the created <img>-tag.

> Technical Note: html_image requires a hit to the disk to read the image and calculate the height and width. If you don't use template caching, it is generally better to avoid html_image and leave image tags static for optimal performance.

Example 8-7. html_image example
`<?php require('Smarty.class.php'); $smarty = new Smarty; $smarty->display('index.tpl'); ?>`
where index.tpl is:
    {html_image file="pumpkin.jpg"}
    {html_image file="/path/from/docroot/pumpkin.jpg"}
    {html_image file="../path/relative/to/currdir/pumpkin.jpg"}
a possible output would be:
    <img src="pumpkin.jpg" alt="" border="0" width="44" height="68" />
    <img src="/path/from/docroot/pumpkin.jpg" alt="" border="0" width="44" height="68" />
    <img src="../path/relative/to/currdir/pumpkin.jpg" alt="" border="0" width="44" height="68" />

Prev | Home | Next
html_checkboxes | Up | html_options