English 中文(简体)
动态显示网站上文件夹中的图像。使用Smarty的Foreach
原标题:Display images from a folder on website dynamically. Foreach using Smarty

I want to display random images from a folder on my website example: ../images/ I already thought of using a foreach construction only I don t know how to implement it in the code.

<ul>
{foreach from=../images/ item=imagelink}

<li><img src="{$imagelink}" width="100" height="100" alt=""/></li>

{foreach}
</ul>

我希望有人有一个解决方案,我已经搜索了很多,但找不到解决方案。

我还想稍后显示该文件夹中的所有图像。

问题回答

您可能想要在PHP中创建随机图像列表,然后将数组分配给Smarty变量。然后,您将能够使用foreach迭代数组并创建列表元素。

<?php

// create array of random images into $images
$smarty->assign(images, $images);

?>


{* template *}
<ul>
    {foreach from=$images item=image}
        <li><img src="{$image}"/></li>
    {/foreach}
</ul>

@paul delre工作正常,所以我获取了该目录中所有图像的url

$files = glob("img/*.*"); 

$smarty->assign(images, $files);

感谢您的帮助:-)





相关问题
Using QCView and iSight to capture image

I have a QCView that loads a Quartz file which gives you iSights feedback (basically like a QTCaptureView) Everything displays fine The button simply takes a snapshot using the following simple ...

Taking picture with QTCaptureView

Is it possible to simply take a picture and save it somewhere using a QTCaptureView and Apple s built-in iSight? I ve seen lots of tutorials on recording video but none on simply taking a picture. Any ...

Transform rectangular image into trapezoid

In .NET how can I transform an image into a trapezoid. The Matrix class supports rotation, shear, etc, but I can t see a trapezoidal transformation. I m using the usual System.Drawing.* API, but I m ...

Rotate image through Y-axis on web page

What are my options for rotating an image on a web page through the Y-axis? I m not sure if I even have the terminology right. Is this called a rotate or a transform. Most of the searches that I ve ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

Convert from 32-BPP to 8-BPP Indexed (C#)

I need to take a full color JPG Image and remap it s colors to a Indexed palette. The palette will consist of specific colors populated from a database. I need to map each color of the image to it s "...

热门标签