Home php教程 php手册 dedecms模版制作使用方法

dedecms模版制作使用方法

Jun 13, 2016 pm 12:32 PM
dedecms code Instructions make engine mark Overview template stencil specification parse design


解析引擎概述  模板设计规范  代码参考
标记参考: arclist(artlist,likeart,hotart,imglist,imginfolist,coolart,specart) field channel mytag vote friendlink mynews loop channelartlist page list pagelist pagebreak fieldlist 

一、织梦模板解析引擎概述 在了解DedeCms的模板代码之前,了解一下织梦模板引擎的知识是非常有意义的。织梦模板引擎是一种使用XML名字空间形式的模板解析器,使用织梦解析器解析模板的最大好处是可以轻松的制定标记的属性,感觉上就像在用HTML一样,使模板代码十分直观灵活,新版的织梦模板引擎不单能实现模板的解析还能分析模板里错误的标记。

1、织梦模板引擎的代码样式有如下几种形式:
{dede:标记名称 属性='值'/}
{dede:标记名称 属性='值'}{/dede:标记名称}
{dede:标记名称 属性='值'}自定义样式模板(InnerText){/dede:标记名称}

提示:
对于{dede:标记名称 属性='值'}{/dede:标记名称}这种形式的标记,在2.1版中,表示结束只需要用“{/dede}”,但
V3中需要严格用“{/dede:标记名称}”,否则会报错。

2、织梦模板引擎内置有多个系统标记,这些系统标记在任何场合都是能直接使用的。

(1) global 标记,表示获取一个外部变量,除了数据库密码之外,能调用系统的任何配置参数,形式为:
{dede:global name='变量名称'}{/dede:global}

{dede:global name='变量名称' /}

其中变量名称不能加 $ 符号,如变量 $cfg_cmspath ,应该写成 {dede:global name='cfg_cmspath' /} 。

(2) foreach 用来输出一个数组,形式为:
{dede:foreach array='数组名称'}[field:key/] [field:value/]{/dede:foreach}

(3) include 引入一个文件,形式为:
{dede:include file='文件名称' /}
对文件的搜索路径为顺序为:绝对路径、include文件夹,CMS安装目录,CMS主模板目录

3、织梦标记允许在任何标记中使用函数对得到的值进行处理,形式为:
{dede:标记名称 属性='值' function='youfunction("参数一","参数二","@me")'/}
其中 @me 用于表示当前标记的值,其它参数由你的函数决定是否存在,例如:
{dede:field name='pubdate' function='strftime("%Y-%m-%d %H:%M:%S","@me")' /}

二、DedeCms 模板制作规范

  DedeCms系统的模板是非固定的,用户可以在新建栏目时可以自行选择栏目模板,官方仅提供最基本的默认模板,即是内置系统模型的各个模板,DedeCms支持自定义频道模型,用户自定义新频道模型后,需要按该模型设计一套新的模板。
一、概念,设计和使用模板,必须要理解下面几个概念:
1、板块(封面)模板:
  指网站主页或比较重要的栏目封面使用的模板,一般用“index_识别ID.htm”命名,此外,用户单独定义的单个页面或自定义标记,也可选是否支持板块模板标记,如果支持,系统会用板块模板标记引擎去解析后才输出内容或生成特定的文件。
2、列表模板:
  指网站某个栏目的所有文章列表的模板,一般用 “list_识别ID.htm” 命名。
3、档案模板:
  表示文档查看页的模板,一般用 “article_识别ID.htm” 命名。
4、其它模板:
  一般系统常规包含的模板有:主页模板、搜索模板、RSS、JS编译功能模板等,此外用户也可以自定义一个模板创建为任意文件。
二、 命名,为了规范起见,织梦官方建议使用统一的方式来命名模板,具体如下:
1、模板保存位置:
  模板目录:{cmspath/templets/样式名称(英文,默认为default,其中system为系统底层模板,plus为插件使用的模板)/具体功能模板文件}
  一般的模板位置:“/templets/default”
2、 模板文件命名规范:
(1)index_识别ID.htm: 表示板块(栏目封面)模板;
(2)list_识别ID.htm: 表示栏目列表模板;
(3)article_识别ID.htm: 表示内容查看页(文档模板,包括专题查看页);
(4)search.htm: 搜索结果列表模板; 
(5)index.htm: 主页模板; 
注解:
你的系统各个内容频道的[识别ID]分别为: 
例:list_image.htm 表示是就是内容类型为图片集的栏目默认列表模板。

三、主要标记参考

1、arclist 标记

这个标记是DedeCms最常用的一个标记,其中 hotart、coolart、likeart、artlist、imglist、imginfolist、specart 这些标记都是由这个标记所定义的不同属性延伸出来的。

作用:获取一个指定的文档列表

适用范围:封面模板、列表模板、文档模板

(1)基本语法:

{dede:arclist
typeid='' row='' col='' titlelen='' 
infolen='' imgwidth='' imgheight='' listtype='' orderby='' keyword=''}

自定义样式模板(InnerText)

{/dede:arclist}

本标记等同于artlist、imglist、imginfolist标记,其中与artlist是完全等同的,与imglist、imginfolist仅是默认的底层模板不同。


(2)属性参考:

[1] typeid='' 表示栏目ID,在列表模板和档案模板中一般不需要指定,在封面模板中允许用","分开表示多个栏目;
[2] row='' 表示返回文档行数,如果和col联合使用,刚结果数等于row * col;
[3] col='' 表示分多少列显示(默认为单列);
[4] titlelen='' 表示标题长度;
[5] infolen='' 表示内容简介长度;
[6] imgwidth='' 表示缩略图宽度;
[7] imgheight='' 表示缩略图高度;
[8] type='' 表示档案类型,其中默认值或type='all'时为普通文档
§ type='commend'时,表示推荐文档,等同于
§ type='image'时,表示必须含有缩略图片的文档
[9] orderby='' 表示排序方式,默认值是 senddate 按发布时间排列。 
§ orderby='hot' 或 orderby='click' 表示按点击数排列
§ orderby='pubdate' 按出版时间排列(即是前台允许更改的时间值)
§ orderby='sortrank' 按文章的新排序级别排序(如果你想使用置顶文章则使用这个属性)
§ orderby='id' 按文章ID排序
[10] keyword='' 表示含有指定关键字的文档列表,多个关键字用","分开
[11] channelid='数字' 表示特定的频道类型,内置的频道:专题(-1)、文章(1)、图集(2)、Flash(4)、软件(3)
[12] limit='起始,结束' 表示限定的记录范围,row属性必须等于"结束 - 起始",mysql的limit语句是由0起始的,如 “limit 0,5”表示的是取前五笔记录,“limit 5,5”表示由第五笔记录起,取下五笔记录。

(3)底层模板变量

ID(同 id),title,iscommend,color,typeid,ismake,description(同 info),
pubdate,senddate,arcrank,click,litpic(同 picname),typedir,typename,
arcurl(同 filename),typeurl,stime(pubdate 的"0000-00-00"格式),
textlink,typelink,imglink,image

其中:
textlink = title
typelink = typename
imglink = dedecms模版制作使用方法
image = dedecms模版制作使用方法

变量调用方法:[field:varname /]

如:
{dede:arclist infolen='100'}
[field:textlink /]


[field:info /]


{/dede:arclist}

2、field 标记

这个标记用于获取特定栏目或档桉的字段值及常用的环境变量值

适用范围:封面模板、列表模板、文档模板

(1)基本语法

{dede:field name=''/}

(2) name 属性的值:

板块模板:phpurl,indexurl,indexname,templeturl,memberurl,powerby,webname,specurl

列表模板:position,title,phpurl,templeturl,memberurl,powerby,indexurl,indexname,specurl,栏目表dede_arctype的所有字段
其中 position 为 “栏目一 > 栏目二” 这样形式的链接,title则为这种形式的标题

文档模板:position,phpurl,templeturl,memberurl,powerby,indexurl,indexname,specurl,id(同 ID,aid),档案dede_archives表和附加表的所有字段。


3、channel 标记

用于获取栏目列表

适用范围:封面模板、列表模板、文档模板

(1)基本语法
{dede:channel row='' type=''}
自定义样式模板(InnerText)
{/dede:channel}

(2)属性

[1] row='数字' 表示获取记录的条数(通用在某级栏目太多的时候使用,默认是 8)

[2] type = top,sun,self

type='top' 表示顶级栏目
type='sun' 表示下级栏目
type='self' 表示同级栏目

其中后两个属性必须在列表模板中使用。

(3)底层模板变量

ID,typename,typedir,typelink(这里仅表示栏目的网址)

例:
{dede:channel type='top'}
[field:typename/] 
{/dede:channel}

4、mytag 标记

用于获取自定义标记的内容

适用范围:封面模板、列表模板、文档模板

(1)基本语法

{dede:mytag typeid='' name='' ismake='' /}

(2)属性

[1] typeid = '数字' 表示栏目ID,默认为 0,在没有设定的栏目没有定义这个名称的标记,会按如下搜索方式来搜索“先向上查找父栏目 -> 通用标记(typeid=0)的同名标记”。

[2] name = '' 标记名称。

[3] ismake = yes|no 默认为 no 表示mytag里的内容不包含其它封面模板的标记,yes则表示标记内容含有其它封面模板标记。

5、vote 标记

用于获取一组投票表单

适用范围:封面模板

(1) 基本语法
{dede:vote id='投票ID' line style="max-width:90%"
tablewidth='100%' titlebgcolor='#EDEDE2'
titlebackground='' tablebgcolor='#FFFFFF'}
{/dede:vote}


6、friendlink 标记,等同 flink

用于获取友情链接

适用范围:封面模板

(1)基本语法

{dede:flink type='' row='' col='' titlelen='' tablestyle=''}{/dede:flink}
属性注解:
[1]type:链接类型,值:
a. textall 全部用文字显示
b. textimage 文字和图得混合排列
c. text 仅显示不带Logo的链接
d. image 仅显示带Logo的链接
-------------------------------------
[2]row:显示多少行,默认为4行
[3]col:显示多少列,默认为6列
[4]titlelen:站点文字的长度
[5]tablestyle: 表示 



7、mynews 标记

用于获取站内新闻

适用范围:封面模板

(1) 基本语法

{dede:mynews row='条数' titlelen='标题长度'}Innertext{/dede:mynews}

Innertext支持的字段为:[field:title /],[field:writer /],[field:senddate /](时间),[field:body /]

8、loop 标记

用于调用任意表的数据,一般用于调用论坛贴子之类的操作,请参阅论坛扩展插件。

9、channelartlist 标记

用于获取频道的下级栏目的内容列表

适用范围:封面模板

语法:

{dede:channelArtlist typeid=0 col=2 tablewidth='100%'}








{dede:type}






dedecms模版制作使用方法
[field:typename /]

更多...

{/dede:type}

{dede:arclist row="8"}
·[field:title /]

{/dede:arclist}

 

{/dede:channelArtlist}

channelArtlist 是唯一一个可以直接嵌套其它标记的标记,不过仅限于嵌套

{dede:type}{/dede:type} 和 {dede:arclist}{/dede:arclist}

标记。

(1) 属性
typeid=0 频道ID,默认的情况下,嵌套的标记使用的是这个栏目ID的下级栏目,如果你想用特定的栏目,可以用","分开多个ID。

col=2 分多列显示

tablewidth='100%' 外围表格的大小


10、page 标记

表示分页页面的附加参数

适用范围:列表模板

语法:

{dede:page pagesize="每页结果条数"/}

11、list 标记

表示列表模板里的内容列表

语法:

{dede:list col='' titlelen='' 
infolen='' imgwidth='' imgheight='' orderby=''}{/dede:list}

底层模板变量

ID(同 id),title,iscommend,color,typeid,ismake,description(同 info),
pubdate,senddate,arcrank,click,litpic(同 picname),typedir,typename,
arcurl(同 filename),typeurl,stime(pubdate 的"0000-00-00"格式),
textlink,typelink,imglink,image

12、pagelist 标记

表示分页页码列表

适用范围:列表模板

语法:

{dede:pagelist listsize="3"/}

listsize 表示 [1][2][3] 这些项的长度 x 2 

13、pagebreak 标记

用途:表示文档的分页链接列表。
适用范围:仅文档模板。 
语法:{dede:pagebreak /} 

14、 fieldlist 标记
用途:获得附加表的所有字段信息。
适用范围:仅文档模板。 
语法:
{dede:fieldlist}
[field:name /] : [field:value /] 

{/dede:fieldlist}

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZTE 5G portable Wi-Fi U50S goes on sale for NT$899 at first launch: top speed 500Mbps ZTE 5G portable Wi-Fi U50S goes on sale for NT$899 at first launch: top speed 500Mbps Apr 26, 2024 pm 03:46 PM

According to news on April 26, ZTE’s 5G portable Wi-Fi U50S is now officially on sale, starting at 899 yuan. In terms of appearance design, ZTE U50S Portable Wi-Fi is simple and stylish, easy to hold and pack. Its size is 159/73/18mm and is easy to carry, allowing you to enjoy 5G high-speed network anytime and anywhere, achieving an unimpeded mobile office and entertainment experience. ZTE 5G portable Wi-Fi U50S supports the advanced Wi-Fi 6 protocol with a peak rate of up to 1800Mbps. It relies on the Snapdragon X55 high-performance 5G platform to provide users with an extremely fast network experience. Not only does it support the 5G dual-mode SA+NSA network environment and Sub-6GHz frequency band, the measured network speed can even reach an astonishing 500Mbps, which is easily satisfactory.

Retro trend! HMD and Heineken jointly launch flip phone: transparent shell design Retro trend! HMD and Heineken jointly launch flip phone: transparent shell design Apr 17, 2024 pm 06:50 PM

According to news on April 17, HMD teamed up with the well-known beer brand Heineken and the creative company Bodega to launch a unique flip phone - The Boring Phone. This phone is not only full of innovation in design, but also returns to nature in terms of functionality, aiming to lead people back to real interpersonal interactions and enjoy the pure time of drinking with friends. Boring mobile phone adopts a unique transparent flip design, showing a simple yet elegant aesthetic. It is equipped with a 2.8-inch QVGA display inside and a 1.77-inch display outside, providing users with a basic visual interaction experience. In terms of photography, although it is only equipped with a 30-megapixel camera, it is enough to handle simple daily tasks.

Honor Magic V3 debuts AI defocus eye protection technology: effectively alleviates the development of myopia Honor Magic V3 debuts AI defocus eye protection technology: effectively alleviates the development of myopia Jul 18, 2024 am 09:27 AM

According to news on July 12, the Honor Magic V3 series was officially released today, equipped with the new Honor Vision Soothing Oasis eye protection screen. While the screen itself has high specifications and high quality, it also pioneered the introduction of AI active eye protection technology. It is reported that the traditional way to alleviate myopia is "myopia glasses". The power of myopia glasses is evenly distributed to ensure that the central area of ​​​​sight is imaged on the retina, but the peripheral area is imaged behind the retina. The retina senses that the image is behind, promoting the eye axis direction. grow later, thereby deepening the degree. At present, one of the main ways to alleviate the development of myopia is the "defocus lens". The central area has a normal power, and the peripheral area is adjusted through optical design partitions, so that the image in the peripheral area falls in front of the retina.

Teclast M50 Mini tablet is here: 8.7-inch IPS screen, 5000mAh battery Teclast M50 Mini tablet is here: 8.7-inch IPS screen, 5000mAh battery Apr 04, 2024 am 08:31 AM

According to news on April 3, Taipower’s upcoming M50 Mini tablet computer is a device with rich functions and powerful performance. This new 8-inch small tablet is equipped with an 8.7-inch IPS screen, providing users with an excellent visual experience. Its metal body design is not only beautiful but also enhances the durability of the device. In terms of performance, the M50Mini is equipped with the Unisoc T606 eight-core processor, which has two A75 cores and six A55 cores, ensuring a smooth and efficient running experience. At the same time, the tablet is also equipped with a 6GB+128GB storage solution and supports 8GB memory expansion, which meets users’ needs for storage and multi-tasking. In terms of battery life, M50Mini is equipped with a 5000mAh battery and supports Ty

Vivo's phone with the strongest signal! vivo X100s is equipped with a universal signal amplification system: 21 antennas, 360° surround design Vivo's phone with the strongest signal! vivo X100s is equipped with a universal signal amplification system: 21 antennas, 360° surround design Jun 03, 2024 pm 08:41 PM

According to news on May 13, vivoX100s was officially released tonight. In addition to excellent images, the new phone also performs very well in terms of signal. According to vivo’s official introduction, vivoX100s uses an innovative universal signal amplification system, which is equipped with up to 21 antennas. This design has been re-optimized based on the direct screen to balance many signal requirements such as 5G, 4G, Wi-Fi, GPS, and NFC. This makes vivoX100s the mobile phone with the strongest signal reception capability in vivo’s history. The new phone also uses a unique 360° surround design, with antennas distributed around the body. This design not only enhances the signal strength, but also optimizes various daily holding postures to avoid problems caused by improper holding methods.

Honor X60i mobile phone is on sale starting from 1,399 yuan: visual quadrilateral OLED direct screen Honor X60i mobile phone is on sale starting from 1,399 yuan: visual quadrilateral OLED direct screen Jul 29, 2024 pm 08:25 PM

According to news on July 29, the Honor X60i mobile phone is officially on sale today, starting at 1,399 yuan. In terms of design, the Honor X60i mobile phone adopts a straight screen design with a hole in the center and almost unbounded ultra-narrow borders on all four sides, which greatly broadens the field of view. Honor X60i parameters Display: 6.7-inch high-definition display Battery: 5000mAh large-capacity battery Processor: Dimensity 6080 processor (TSMC 6nm, 2x2.4G A76+6×2G A55) System: MagicOS8.0 system Other features: 5G signal enhancement, smart capsule, under-screen fingerprint, dual MIC, noise reduction, knowledge Q&A, photography capabilities: rear dual camera system: 50 million pixels main camera, 2 million pixels auxiliary lens, front selfie lens: 8 million pixels, price: 8GB

New stacking process! Xiaomi MIX Fold 4 is equipped with Jinshajiang 'three-dimensional special-shaped' battery for the first time New stacking process! Xiaomi MIX Fold 4 is equipped with Jinshajiang 'three-dimensional special-shaped' battery for the first time Jul 20, 2024 am 03:20 AM

According to news on July 19, Xiaomi MIX Fold 4, the first flagship folding new phone, was officially released tonight and is equipped with a "three-dimensional special-shaped battery" for the first time. According to reports, Xiaomi MIX Fold4 has achieved a major breakthrough in battery technology and designed an innovative "three-dimensional special-shaped battery" specifically for folding screens. Traditional folding screen devices mostly use conventional square batteries, which have low space utilization efficiency. In order to solve this problem, Xiaomi did not use the common winding battery cells, but developed a new lamination process to create a new form of battery, which greatly improved the space utilization. Battery Technology Innovation In order to accurately alternately stack positive and negative electrode sheets and ensure the safe embedding of lithium ions, Xiaomi has developed a new ultrasonic welding machine and lamination machine to improve welding and cutting accuracy.

Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Tsinghua University and Zhipu AI open source GLM-4: launching a new revolution in natural language processing Jun 12, 2024 pm 08:38 PM

Since the launch of ChatGLM-6B on March 14, 2023, the GLM series models have received widespread attention and recognition. Especially after ChatGLM3-6B was open sourced, developers are full of expectations for the fourth-generation model launched by Zhipu AI. This expectation has finally been fully satisfied with the release of GLM-4-9B. The birth of GLM-4-9B In order to give small models (10B and below) more powerful capabilities, the GLM technical team launched this new fourth-generation GLM series open source model: GLM-4-9B after nearly half a year of exploration. This model greatly compresses the model size while ensuring accuracy, and has faster inference speed and higher efficiency. The GLM technical team’s exploration has not

See all articles