を使用する CMS Made simple でテンプレートを作成していSmarty engine
ます。私は完全な smarty/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-->
誰かがこれで私を助けてくれますか? 私は本当にこの問題に行き詰まっています。前もって感謝します..