Say in your fields.ini of your delegate class you have:
The attribute url tells Xataface where in the application the images for this field are found. If you put your default image in this folder, then there are a number ways to make a default image appear. The idea is you don't want to have to hardcode the directory path into the code/template, but rather use that attribute in the fields.ini file (except for method 3).
- Method 1: Using the PHP function dirname()
You can have an if statement which checks if there is an image, and if not then use the directory path of the folder containing your default image:
if (!$record->display('image'))
$default = dirname($record->display('image')).'/default.jpg'; - Method 2: Directly access the url attribute from the fields.ini file
$fld = $record->_table->getField('image');
$default = $fld['url'].'/default.jpg'; - Method 3: Move the image the default xataface image folder.
Not really a method, but you can just place the default image in another folder and rely on Xataface's environment variables to help you. Say you want to display a default image in the event there is no image. You do this in the smarty template:
{if $row->val('image') }
<img src="{$row->display('image')}?max_height=100&max_width=100" />
{else}
<img src="{$ENV.DATAFACE_SITE_URL}/images/default_tire.jpg?max_height=100&max_width=100" />
{/if}
No comments:
Post a Comment