Thu, September 23, 2021
 
https://devcodepro.comdevcodepro
X
Home · Latest · Trends
3

Random image in Smarty file

Display random image in Smarty template file
//php file
$smarty->assign('random', 
  array( 
    'photo1.jpg', 
    'photo2.jpg', 
    'photo3.jpg',
    'photo4.jpg'
  ));

//template file
<style>
{literal}
.myImageDiv {
background: url({/literal}{$siteurl}/themes/{$style}/styles/images/{$random.$randomimage}{literal}) no-repeat transparent;
height: 460px;
background-size: cover;
background-position: center;
}
{/literal}
</style>
rated 3 times (3) (0)
comments: 0 / hits: 1869  / 4 years ago, thu, may 25, 17, 01:29:47
More From » PHP
 

Comments

There are no comments for this Snippet yet
Only authorized users can post. Please sign in first, or register a free account
 
Share
Posted
Ronald
Member since Sep 6, 2016
Total Code Snippets: 25
Total Comments: 2
Location: New Britain, Connecticut
Ronald snippets
5 years ago, tue, sep 6, 16, 10:11:38
comments: 0 / hits: 2571
PHP
5 years ago, tue, sep 6, 16, 10:18:23
comments: 0 / hits: 2425
PHP
5 years ago, tue, sep 6, 16, 10:42:24
comments: 0 / hits: 2791
PHP
5 years ago, fri, sep 16, 16, 1:10:12
comments: 0 / hits: 3230
PHP
5 years ago, fri, sep 16, 16, 1:12:32
comments: 0 / hits: 2144
CSS
5 years ago, fri, sep 16, 16, 1:27:33
comments: 0 / hits: 3232
PHP
5 years ago, sun, sep 25, 16, 2:52:42
comments: 1 / hits: 2560
5 years ago, thu, nov 10, 16, 4:21:59
comments: 1 / hits: 2707
PHP
5 years ago, mon, nov 21, 16, 10:48:23
comments: 2 / hits: 9437
PHP