我正在 CMS Made simple 中构建一个模板,它使用Smarty engine
. 我是一个完全聪明/php 的新手。
我正在遍历文件夹中的图像并将它们显示在Bootstrap Carusel
. 那工作正常。
另一方面,我必须为每个图像显示文本和标题。
我想出了一个解决方案,在.txt
文件夹中放置一个包含每个图像的标题和文本内容的文件。例如,我有一个在同一个文件夹中img1.jpg
调用img1.txt
的文件(img2.jpg
- img2.txt
,img3.jpg
-img3.txt
等)。每个图像都有一个相应的.txt
文件,其中包含必须读取到下面代码中的标题和文本部分的内容)
我不确定如何实施该解决方案{foreach}
并需要帮助。
我一直在使用下面的这段代码来访问,.txt
但使用*.txt
不起作用。*.txt
给出一个空数组。
更新
{"{uploads_url}/images/{$entry->Picfolder}/*.txt"|file_get_contents|parse_str:$result|glob}
{foreach from=$result key=text item=foo}
<p>{$text}</p>
{/foreach}
这是整个轮播代码:
<!--Carousel Wrapper-->
<div id="carousel-thumb" class="carousel slide carousel-fade carousel-thumbnails" data-ride="carousel">
<!--Slides-->
<div class="carousel-inner" role="listbox">
{assign var='pics' value="uploads/images/{$entry->Picfolder}/*.jpg"|glob} <!--finding all .jpgs in the folder -->
{foreach from=$pics item='pic'}<!-- loop through .jpgs -->
{if $pic@first}
<div class="carousel-item active">
{else}
<div class="carousel-item">
{/if}
<img class="d-block w-100" src='{root_url}/{$pic}' alt="First slide"> <!-- add jpgs from loop -->
<div class="carousel-caption d-md-block">
<h5>Caption</h5><!-- need to insert content from .txt file here -->
<p>Image text</p><!-- need to insert content from .txt file here -->
</div>
</div>
{/foreach}
</div>
<!--/.Slides-->
<!--Controls-->
<a class="carousel-control-prev" href="#carousel-thumb" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carousel-thumb" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
<!--/.Controls-->
<ol class="carousel-indicators">
{foreach from=$pics item='pic' name=img}
<li data-target="#carousel-thumb" data-slide-to="{$smarty.foreach.img.index}" class="active"> <img class="d-block w-100" src='{root_url}/{$pic}' height="50" width="50" class="img-fluid"></li>
{/foreach}
</ol>
</div>
<!--/.Carousel Wrapper-->
有人可以帮我吗?我真的被这个问题困住了。提前致谢..