網誌分頁

COLDFUSION – 客製化標籤 (Custom Tag)

今天在逛Adobe Live Docs的時候,想想custom tag 一直沒有機會用到,所以也沒學到。其實custom tag跟CFINCLUDE很類似,可是比CFINCLUDE來的好控制、嚴謹。

首先,先要做一個頁面是處理TAG的程式頁面,這個範例是做一個客製的DATEFORMAT標籤,存成同目錄或者用CF管理頁面控制客製化標籤的歸檔檔案夾。這個範例我存成dateformat.cfm,當然也可以存成其他目錄,然後用cfmodule,就可以相關路徑呼叫你的程式頁面

1
2
3
	<cfscript>
	caller.cf_dateformat=dateformat(attributes.date,attributes.format);
	</cfscript>

caller的stuct是所呼叫頁面的變數,很像本頁面的variable的概念,我習慣把回傳值取名與標簽名字一樣,有模仿Allaire Macromedia Adobe的作風。到時候用#標籤名字#來展示就好了,這樣也不會忘記變數名字

再來就是呼叫這個程式的客製化標籤,呼叫的時候,是用

1
2
3
4
	<cf_dateformat format="yyyy-mm-dd" date="#now()#" />
	<cfoutput>
		#cf_dateformat#
	</cfoutput>

No related posts.

1 comment to COLDFUSION – 客製化標籤 (Custom Tag)

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>