Support Forums

Smarty functions

This is a discussion on Smarty functions within the Modules / Plugins / Modifications forums, part of the Developer Forums category; I have a wish to set the alt tag on images in viewlistings according to a simple function which I ...


Go Back   68 Classifieds Forums > Developer Forums > Modules / Plugins / Modifications

Reply
 
Thread Tools Display Modes
Old 08-18-2008, 04:57 PM   #1
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 1,973
Rep Power: 48
seymourjames has a spectacular aura about
Default Smarty functions

I have a wish to set the alt tag on images in viewlistings according to a simple function which I would like to return an array.

Here is a function which I want to return an array phrases which have been mixed up.

<?php
function smarty_function_randphrase($params, &$smarty)
{
$phrase = array("Property In France", "French Property", "French Property For Sale", "Property In France For Sale", "Property For Sale In France ", "Property In France", "French Properties", "French Properties For Sale", "Properties In France For Sale", "Properties For Sale In France ");

shuffle($phrase);

return $phrase; is this correct?
}
?>

In viewlisting, I would like to add an alt tag from the output of the array.


{html_table_adv loop=$data cols=$cols table_attr='width="100%"'}
<div class="photo_view">
<div class="feat_img"><img src="photos/[[image]]" width="254" height="218" class="image" border="0" alt="[[randphrase]]" /></div>
<div class="photo_text">[[title]]</div></div>
{/html_table_adv}

I just cannot get the syntax. Any help would be greatly appreciated.
__________________
TemplateCodes.com for 68 Classifieds & Magento Online Stores
seymourjames is offline   Reply With Quote
Old 08-18-2008, 05:06 PM   #2
68 Classifieds Staff
 
Eric Barnes's Avatar
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 5,266
Rep Power: 124
Eric Barnes is a jewel in the rough
Default

Try this:
PHP Code:

<?php
function smarty_function_randphrase($params, &$smarty)
{
$phrase = array("Property In France""French Property""French Property For Sale""Property In France For Sale""Property For Sale In France ""Property In France""French Properties""French Properties For Sale""Properties In France For Sale""Properties For Sale In France ");

return 
shuffle($phrase);
}
?>
Then: alt="{randphrase}"
__________________
Eric Barnes
68 Classifieds Developer
Customer Area | Issue Tracker | Documentation | 68C Mods | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Old 08-18-2008, 05:44 PM   #3
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 1,973
Rep Power: 48
seymourjames has a spectacular aura about
Default

Better but I get a bunch of alt = "1" in the tags. I do not get the array strings. Any more ideas. Bring back 'C' is what I say. i think it is something in the alt="{randphrase}" which is not gelling. I want to eventually use this to generate tags when people do not enter descriptions on their photos. Bare or empty alt tags is not so good.
__________________
TemplateCodes.com for 68 Classifieds & Magento Online Stores

Last edited by seymourjames; 08-18-2008 at 05:46 PM.
seymourjames is offline   Reply With Quote
Old 08-18-2008, 05:53 PM   #4
68 Classifieds Staff
 
Eric Barnes's Avatar
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 5,266
Rep Power: 124
Eric Barnes is a jewel in the rough
Default

How about this:
PHP Code:
 
<?php
function smarty_function_randphrase($params, &$smarty)
{
$phrase = array("Property In France""French Property""French Property For Sale""Property In France For Sale""Property For Sale In France ""Property In France""French Properties""French Properties For Sale""Properties In France For Sale""Properties For Sale In France ");

$rand_keys array_rand($phrase2);
return 
$phrase[$rand_keys[0]];
}
?>
__________________
Eric Barnes
68 Classifieds Developer
Customer Area | Issue Tracker | Documentation | 68C Mods | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Old 08-18-2008, 05:58 PM   #5
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 1,973
Rep Power: 48
seymourjames has a spectacular aura about
Default

Very nearly. alt ="Property In France" each time it goes through the loop. Just a case now of getting it to move along the array the same number of times as there are images to be displayed.
__________________
TemplateCodes.com for 68 Classifieds & Magento Online Stores
seymourjames is offline   Reply With Quote
Old 08-18-2008, 06:05 PM   #6
68 Classifieds Staff
 
Eric Barnes's Avatar
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 5,266
Rep Power: 124
Eric Barnes is a jewel in the rough
Default

Ok how about this:
PHP Code:
  
<?php
function smarty_function_randphrase($params, &$smarty)
{
$phrase = array("Property In France""French Property""French Property For Sale""Property In France For Sale""Property For Sale In France ""Property In France""French Properties""French Properties For Sale""Properties In France For Sale""Properties For Sale In France ");
$i rand(08);
return 
$phrase[$i];
}
?>
The $i=rand(0,8); 8 is the number of array elements.
__________________
Eric Barnes
68 Classifieds Developer
Customer Area | Issue Tracker | Documentation | 68C Mods | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Addition of new functions() archavir Technical Support 0 04-24-2008 04:52 PM
Module smarty plugins are not available marketingsolutions v3.1 Questions & Support 3 03-12-2008 10:33 AM
Smarty Templates and You. Posted BY Lhotch Eric Barnes Templates, HTML, CSS, and Design Help 13 10-02-2007 09:06 AM
Help with Smarty custom functions Nealm v3.1 Modules & Modifications 2 07-09-2007 09:55 PM


All times are GMT -4. The time now is 08:40 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0