Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 23-07-2008, 02:18 PM
hymns's Avatar
Senior Webmaster
 
Join Date: Nov 2001
Location: Johor
Posts: 768
Rep Power: 100
hymns is on a distinguished road
Send a message via ICQ to hymns Send a message via Yahoo to hymns
Colfusion Template Engine Component

Assalamualaikum!!

Hoh lama beno rasa teman tak post kat sini. Nah hari ni teman saje nak post coldfusion template engine component kat sini untuk dikongsi bersama2. Teman buat component ni masa teman ngajar coldfusion kat melaka.

Component ni boleh fungsinya lebih kurang xtemplate (php). Tapi ni adaptasi ke coldfusion. Walaupun coldfusion ni tags language ada gak la designer2 teman padam cftags ni. Dia kata ni bukan html punya tags. Hehe...

Tengok2 lah sape2 coldfusion developer tu. Ha ni teman nak ingatkan ni bukan framework arr. Component ni cuma salah satu dari MVC (Model View Controller) iaitu View je. Hehe...

DOWNLOAD TEMPLATECFC
Versi: 1.8.8

Example 1 (simple assign)
user.cfm
Code:
<cfset name = "Muhammad Hamizi Jaminan">
<cfset nickname = "hymns">

<cfset tpl = createobject("component", "templatecfc")>
<cfset tpl.init("user.html")>

<cfset tpl.assign("name", name)>
<cfset tpl.assign("nickname", nickname)>

<cfset output = tpl.parse("true")>

<cfoutput>#output#</cfoutput>
user.html
HTML Code:
<head>
<body>
My name is {fullname}. You also can call me {nickname}
</body>
</html>
Browser Ouput
My name is Muhammad Hamizi. You also call me hymns

Example 2 (Query & Array)
query.cfm
Code:
<cfquery name="myquery">
select id, username, phone, email from tbl_users
</cfquery>

<cfset myarray = arraynew(1)>
<cfset myarray[1] = "ice tea">
<cfset myarray[2] = "hot tea">
<cfset myarray[3] = "hot coffee">
   
<cfset tpl = createobject("component", "templatecfc")>
<cfset tpl.init("query.html")>

<cfset tpl.assign("data", myquery)>

<cfset tpl.assign("drink", myarray)>

<cfset output = tpl.parse("true")>

<cfoutput>#output#</cfoutput>
query.html
HTML Code:
<head>
<body>
<h3>User List</h3>
<table border="1" width="100%">
    <tr>
        <td>ID</td>
        <td>Username</td>
        <td>Phone</td>
        <td>Email</td>
    </tr>
    <!-- BEGIN : data -->
    <tr>
        <td>{data.id}</td>
        <td>{data.username}</td>
        <td>{data.phone}</td>
        <td>{data.email}</td>
    </tr>
    <!-- END : data -->
    <tr>
        <td colspan=4>Total Record: {data.recordcount}</td>
    </tr>       
</table>

<h3>Favourite Drink</h3>
<table border=1>
    <!-- BEGIN : drink -->
    <tr>
        <td>{drink}</td>
    </tr>
    <!-- END : drink -->   
</table>
</body>
</head> 
Browser Output
User List
---------------------------------------
| ID | Username | Phone | Email |
---------------------------------------
| 1 | hymns | 1231312 | user@user.com |
---------------------------------------
| 2 | johndoe | 1231231 | user2@user.com |
---------------------------------------
| Total Record: 4 ; ; |
---------------------------------------

Favourite Drink
ice tea
hot tea
hot coffee


Component ni gak boleh guna vars CGI direct terus. Contoh untuk dapatkan ip gunakan tag {CGI.REMOTE_ADDR} atau {CGI.SCOPE} untuk lain-lain coldfusion cgi scope.

Kalau rasa nak fancy2 skit ala2 smarty, teman buat gak function ni untuk BESARKAN HURUF {tagname|upper} atau huruf kecil {tagname|lower}

Untuk sample-sample lain boleh tengok dalam package tu.

Kalau teman-teman kat WM ni ade idea2 nak tambah post2 la kat sini yer. Teman buat ni saja suka2. (sebenarnya teman lebih suka coding PHP tapi banyak yang dah siap. guna ajer)

DOWNLOAD TEMPLATECFC
__________________
I hate when:

vBulletin Message:
Sorry! The administrator has specified that users can only post one message every 60 seconds
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Describe Your JOOMLA Component / Module vedee2006 Website Design 3 12-04-2008 12:43 PM
Template for SALE from $130 onwards! - We also have OS Commerce template! certify Other Webmaster-related Services and Promotion 3 24-04-2007 09:13 AM
template in PHP suzila Website Programming 6 17-02-2003 12:02 PM
Flash MX Component UI? Gemp-X Website Design 9 29-05-2002 02:22 AM
template nuha Website Programming 0 02-05-2002 11:40 AM



All times are GMT +8. The time now is 02:56 AM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.


WebmasterMalaysia.com is Proudly Hosted by Exabytes Semi Dedicated Server.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59