# 模板特殊標簽
CMS內容管理系統的模板中有兩個特殊標簽`{__STYLE__}`和`{__SCRIPT__}`,這兩個標簽出現在`addons/cms/view/default/common/layout.html`布局模板中,那這兩個標簽的作用是將當前頁模板中的
i8tFvT5PYbI+gC9Rpi6QTQ==
~~~
<script data-render="script">JS代碼</script>
~~~
替換到`{__SCRIPT__}`位置
以及
i8tFvT5PYbI+gC9Rpi6QTQ==
~~~
<style data-render="style">CSS樣式</style>
~~~
替換到`{__STYLE__}`位置
i8tFvT5PYbI+gC9Rpi6QTQ==
例如
我們的`layout.html`布局模板代碼如下
i8tFvT5PYbI+gC9Rpi6QTQ==
~~~
<!DOCTYPE html>
<head>
<link rel="stylesheet" media="screen" href="__CDN__/assets/css/bootstrap.min.css"/>
{__STYLE__}
</head>
<body class="group-page">
{__CONTENT__}
<script type="text/javascript" src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
{__SCRIPT__}
</body>
</html>
~~~
我們在`show_news.html`模板中有如下代碼
i8tFvT5PYbI+gC9Rpi6QTQ==
~~~
<style data-render="style">
body{
background:#000;
};
</style>
<script data-render="script">
alert(123);
</script>
<p>這是我們詳情頁正文</p>
~~~
則最終生成的模板代碼為:
i8tFvT5PYbI+gC9Rpi6QTQ==
~~~
<!DOCTYPE html>
<head>
<link rel="stylesheet" media="screen" href="/assets/css/bootstrap.min.css"/>
<style>
body{
background:#000;
};
</style>
</head>
<body class="group-page">
<p>這是我們詳情頁正文</p>
<script type="text/javascript" src="/assets/libs/jquery/dist/jquery.min.js"></script>
<script>
alert(123);
</script>
</body>
</html>
~~~
可以看到`<style data-render="style"></style>`中的代碼已經被替換到`head`中了,而`<script data-render="script"></script>`中的代碼被替換到了body的最尾部。
i8tFvT5PYbI+gC9Rpi6QTQ==
### 溫馨提示
`{__STYLE__}`和`{__SCRIPT__}`必須是大寫,且前后都必須是空行。否則可能會導致替換失敗。
- 介紹
- 標簽手冊
- 全局標簽
- block標簽
- config標簽
- execute標簽
- query標簽
- breadcrumb標簽
- blocklist標簽
- 欄目標簽
- channellist標簽
- channel標簽
- nav標簽
- 文章標簽
- arclist標簽
- archives標簽
- prevnext標簽
- 專題
- speciallist標簽
- special標簽
- 公共參數
- common參數
- include引用
- 單頁
- spagelist標簽
- page標簽
- spageinfo標簽
- 特殊標簽
- tagslist標簽
- tags標簽
- commentlist標簽
- commentinfo標簽
- diyform標簽
- 模板特殊標簽
- 列表頁面
- pagelist標簽
- pageinfo標簽
- pagefilter標簽
- pageorder標簽
- pagelist的相關排序
- 新功能
- 后端新增代碼
- 模板使用
- 二級導航功能
- 共用banner功能
- 后臺站點配置添加編輯器