當前頁可用變量有`$category`,`$article`,`$prev_article`,`$next_article`,這三個變量都是模型對象,取值時可以直接把它當成數組用。
## 輸出`$category`內部的值
`$category`代表當前文章分類
```
{$category.id} <!--輸出分類 id-->
{$category.parent_id} <!--輸出分類父級分類 id-->
{$category.name} <!--輸出分類名稱-->
{$category.description} <!--輸出分類描述-->
{$category.seo_title} <!--輸出分類seo標題-->
{$category.seo_keywords} <!--輸出分類 seo 關鍵字-->
{$category.seo_description} <!--輸出分類 seo 描述-->
```
以上的值也可以當成 php 變量直接輸出,這里只演示一下怎么輸出 id 屬性
```
<php>
echo $category['id']; /*輸出分類 id*/
</php>
```
## 輸出`$article`內部的值
`$article`代表當前文章
```
{$article.id} <!--輸出文章id-->
{$article.is_top} <!--輸出文章置頂狀態,1:置頂;0:不置頂-->
{$article.recommended} <!--輸出文章推薦狀態,1:推薦;0:不推薦-->
{$article.post_hits} <!--輸出文章查看數-->
{$article.post_like} <!--輸出文章點選數-->
{$article.comment_count} <!--輸出文章評論數-->
{$article.create_time} <!--輸出文章創建時間-->
{$article.update_time} <!--輸出文章更新時間-->
{$article.published_time} <!--輸出文章發布時間-->
{$article.post_title} <!--輸出文章標題-->
{$article.post_keywords} <!--輸出文章關鍵字,以英文逗號隔開-->
{$article.post_excerpt} <!--輸出文章摘要-->
{$article.post_content} <!--輸出文章內容-->
```
以上的值也可以當成 php 變量直接輸出,這里只演示一下怎么輸出 id 屬性
```
<php>
echo $article['id']; /*輸出分類 id*/
</php>
```
`$prev_article`代表前上一篇文章,屬性列表和`$article`一樣,這里就不在舉例
`$next_article`代表前下一篇文章,屬性列表和`$article`一樣,這里就不在舉例
## 調用文件縮略圖
```
<notempty name="article.more.thumbnail">
<img src=" {:cmf_get_image_url($article.more.thumbnail)}"/>
</notempty>
```
## 調用文章的相冊
```
<!--調用文章的相冊-->
<notempty name="article.more.photos">
<foreach name="article.more.photos" item="photo">
<img src=" {:cmf_get_image_url($photo.url)}" alt={$photo.name}/>
</foreach>
</notempty>
```
## 調用文章的附件
```
<!--調用文章的附件-->
<notempty name="article.more.files">
<foreach name="article.more.files" item="file">
<a href="{:cmf_get_file_download_url($file.url)}" title={$file.name}>下載文件</a>
</foreach>
</notempty>
```
## 文章 SEO
```
<head>
<title>{$article.post_title}</title>
<meta name="keywords" content="{$site_info.site_seo_keywords|default=''}"/>
<meta name="description" content="{$site_info.site_seo_description|default=''}">
<!--省略...-->
</head>
```
## 創建文章頁模板
在`public/themes/quick_start/portal`目錄下創建`article.html`文件,內容如下:
```
<!DOCTYPE html>
<html>
<head>
<title>{$article.post_title}</title>
<meta name="keywords" content="{$site_info.site_seo_keywords|default=''}"/>
<meta name="description" content="{$site_info.site_seo_description|default=''}">
<include file="public@head"/>
<style>
#article_content img {
height: auto !important;
max-width: 100%;
}
#article_content {
word-wrap: break-word;
}
</style>
</head>
<body class="body-white">
<include file="public@nav"/>
<div class="container">
<div class="row">
<div class="col-md-9">
<div class="tc-box article-box">
<h2>{$article.post_title}</h2>
<div class="article-infobox">
<span>{:date('Y-m-d H:i',$article.published_time)} by {$article.user.user_nickname}</span>
<span>
<a href="javascript:;"><i class="fa fa-eye"></i><span>{$article.post_hits}</span></a>
<a href="{:url('portal/Article/doLike',array('id'=>$article['id']))}" class="js-count-btn"><i
class="fa fa-thumbs-up"></i><span class="count">{$article.post_like}</span></a>
<a href="{:url('user/favorite/add')}"
class="js-favorite-btn"
data-title="{:base64_encode($article.post_title)}"
data-url="{:cmf_url_encode('portal/Article/index',array('id'=>$article['id']))}"
data-table="portal_post"
data-id="{$article['id']}"
>
<i class="fa fa-star-o"></i>
</a>
</span>
</div>
<hr>
<div id="article_content">
{$article.post_content}
</div>
</div>
</div>
<div class="col-md-3">
</div>
</div>
</div>
<include file="public@footer"/>
<include file="public@scripts"/>
</body>
</html>
```
## 添加模板配置文件
在`public/themes/quick_start/portal`目錄下創建`article.json`文件,內容如下:
```
{
"name": "文章頁",
"action": "portal/Article/index",
"description": "文章頁模板文件",
"order": 10.0,
"more": {
"vars": {
}
}
}
```
## 更新模板
至此門戶文章頁模板制作完成。