:::
6-1 將資料庫取出的值帶入樣板
- 在
index.php中,我們有送了一個樣板變數$news到樣板,裡面是完整的新聞資料 - 修改
show.tpl,並實際載入變數值{include file="article.tpl" slider=true title=$news.news_title date=$news.report_date school=$news.school_name count=$news.views author=$news.publisher content=$news.news_content link=$news.related_link thumb=""} - 此時,文字部份應該會出現真正的內容

- 不過內容部份,沒有換行,所以,我們來修改一下
templates/article.tpl將原本的{$content}改為{$content|nl2br}:<article class="my-4"> ...略... <div class="row"> {if $thumb} <div class="col-md-4 mb-3"> <img src="{$thumb}" class="img-fluid" alt="{$title}圖片"> </div> <div class="col-md-8 mb-3"> {$content|nl2br} </div> {else} <div class="col-md-12 mb-3"> {$content|nl2br} </div> {/if} </div> </article> - 如此,看起來有正常一些:

6. 製作顯示單一文章的功能 