330 likes | 471 Vues
ColdFusion Basics. 321483 02-05-2002. Working With Templates. CFML Reference: Online reference to all CFML tags http://nongmon.compsci.buu.ac.th/cfdocs/CFML_Reference/contents.htm. Working With Templates. Templates are ColdFusion Application Pages (programs)
E N D
ColdFusion Basics 321483 02-05-2002
Working With Templates • CFML Reference: • Online reference to all CFML tags http://nongmon.compsci.buu.ac.th/cfdocs/CFML_Reference/contents.htm
Working With Templates • Templates are ColdFusion Application Pages (programs) • All ColdFusion Code is written: • Inside tags • or within the boundaries of paired tags (just like HTML)
Working With Templates • CFML Tags • CFML tags are written in the same manner as HTML tags but they start with CF • Syntax of most CFML tags: <CFTagName> … </CFTagName>
Working With Templates • CFML Tags • Any CFML tag that doesn’t have or require end tag may optionally be written as follow: <CFTagName> • Most CFML tags accept one or more attributes that affect tag’s behavior
Working With Templates • Creating Templates • See Demo With ColdFusion Studio and Practice Support Document • Saving Templates • In Windows Environment, filenames are case-insensitive • On Unix, filenames are case-sensitive • See Demo With ColdFusion Studio and Practice Support Document
Working With Templates • Executing Templates • Type your template URL in the Browser • See Demo
Commenting Your Code • ColdFusion comments begin with tag<!--- and end with tag ---> • Good practice to use comments to provide explanation of your code
Commenting Your Code • HTML-style Comments: • <!- - Your comments - -> • CFML Comments: • <!- - - Your comments - - ->
Using Variables • Variable: • Name associated with a data value • A variable stores or contains a value • In ColdFusion, you don’t have to declare explicitly your variables
Variables and CFSET • <CFSET> Tag: • <CFSET> tag is used to create and assign a value to a variable • Example: • <CFSET Price = 1300.00> • Creates a variable named Price which is assigned the value 1300.00 • If the variable Price exists, <CFSET> resets it to the specified value
Variables and CFSET • <CFSET> Tag: • <CFSET> tag can be used to perform computations • Example: • <CFSET Tax = Price * 0.07> • Creates a variable named Tax which is assigned a value obtained by multiplying variable Price by 0.07 • <CFSET> Syntax
Variable Naming Rules • Variable names must begin with a letter, and can be followed with a combination of letters, numbers, or underscores (_) • Variable names must be one word – they can’t contain spaces • Generally accepted naming rules are to capitalize first letter of each word in the variable name • Variable names are not case sensitive: • i.e. TaxRate and taxrate are the same variable • See more information from CFdoc
Data Types and Variable Types • ColdFusion Data Types include: • Integer • Real Number • String • Boolean • Date and Time • Array • Structure • List • Query • COM Object • See more information from CFdoc
Data Types and Variable Types • Variable Type (Variable Scope) • To be covered later • See more information from CFdoc
Working With Expressions • Expressions • ColdFusion expressions consist of operands and operators • Operands are comprised of constants and variables • Operators are the verbs that act on the operands
Working With Expressions • Arithmetic Expressions • Arithmetic expressions are formed by combining values and/or variables and arithmetic operators in an appropriate manner • String Expression • To be covered later
Working With Expression • Examples of Expressions: • <cfset x=7> <cfset y = 1+(x * 5)^x> • <cfset firstname = "Koffi "> <cfset lastname = "N’DA"> <cfset name = firstname & lastname>
Arithmetic Expressions See more information from CFdoc
Operator Precedence • When evaluating expressions ColdFusion uses standard operator precedence
Operator Precedence • Example: • 20*5-(4+6)^2/(22\3)MOD6^2=?
CFOUTPUT and Pound Sign (#) • The <CFOUTPUT> tag is used to display the value of a variable on a Web page • Variable may be the result of: • An expression, a database query or other operation • Variable name must be enclosed in # (pound sign) when used with <CFOUTPUT> tag • <CFOUTPUT> replaces the variable with it’s current value when web page is returned to the web browser • Two sided tag: <CFOUTPUT></CFOUTPUT>
CFOUTPUT and Pound Sign (#) • Using Pound Sign (#) • ColdFusion treats text delimited by pound signs differently from plain text • When ColdFusion processes an expression, it replaces the text of the expression and the two pound signs around it with its resulting value • See more information from CFdoc
CFOUTPUT and Pound Sign (#) • Example of How to Use CFOUTPUT and #: • See files home1a.cfm and home1b.cfm located at: http://127.0.0.1/demo/
Using Functions • ColdFusion provides a full set of functions for data formatting, string manipulation, and complex computations • Click the following links for more information on functions: • List of functions • Other information on Functions
Using Formatting Functions • ColdFusion provides functions to format numerical values • DollarFormat(expression): • Formats the expression as a monetary amount • DecimalFormat(expression): • Formats the expression producing 2 decimal places
Using Formatting Functions • NumberFormat(expression, mask): • Formats expression based on rules provided in mask • Mask is a string which contains: 9 – place holder for digit . – specifies location of decimal point , - indicates thousands separator
Using Functions • Examples of How to Use Functions:
Exercise • Open file cfbasic1.doc located in the “Class Exercises” folder on the public directory.