ColdFusion Markup Language: Difference between revisions

Content deleted Content added
Rescuing 17 sources and tagging 0 as dead.) #IABot (v2.0
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags
Line 54:
== Syntax ==
CFML tags have a similar format to HTML tags. They are enclosed in [[angle brackets]] (< and >) and generally have zero or more named [[attribute (computing)|attributes]], though some tags (e.g. cfset, cfif) contain an expression rather than attributes. Many CFML tags have bodies; that is, they have beginning and end tags with text to be processed between them. For example:
<sourcesyntaxhighlight lang="cfm">
<cfoutput>
#value# Bob!
</cfoutput> </sourcesyntaxhighlight>
Other tags, such as cfset and cfftp, never have bodies; all the required information goes between the beginning (<) character and the ending (>) character in the form of tag attributes (name/value pairs), as in the example below. If it is legal for tags not to have a body, it is syntactically acceptable to leave them unclosed as in the first example, though many CFML developers choose to self-close tags as in the second example to (arguably) make the code more legible.
<sourcesyntaxhighlight lang="cfm">
<cfset value = "Hello">
<cfset value = "Hello" />
</syntaxhighlight>
</source>
Even if the tag can have a body, including a body may not be necessary in some instances because the attributes specify all the required information. In these cases, as with the second example above, the end tag (and hence, the tag body) may be omitted and the tag may be self-closing as in the following example:<ref>[http://livedocs.adobe.com/coldfusion/6.1/htmldocs/element5.htm Tag syntax] {{webarchive |url=https://web.archive.org/web/20080527095947/http://livedocs.adobe.com/coldfusion/6.1/htmldocs/element5.htm |date=May 27, 2008 }}</ref>
<sourcesyntaxhighlight lang="cfm">
<cfexecute name="C:\\winNT\\System32\\netstat.exe" arguments="-e" outputfile="C:\\Temp\\out.txt" timeout="1" /></sourcesyntaxhighlight>
 
Various tags offer the ability to type-check input parameters (e.g. cffunction, cfparam, cfqueryparam) if the [[programmer]] declares their type specifically. This functionality is used with cfqueryparam to [[information security|secure]] web applications and databases from [[hacker (computer security)|hacker]]s and malicious web requests such as [[SQL injection]].
Line 97:
 
For example, if writing a custom tag to perform [[addition]], taking two attributes and adding them together, the tag would be an addition.cfm file which could look like this:
<sourcesyntaxhighlight lang="cfm">
<cfset caller.addition = attributes.first + attributes.second />
<cfexit method="exitTag" />
</syntaxhighlight>
</source>
 
Assuming the tag is in the same directory as the file (or in a pre-defined customtags directory), it can be invoked thus:
<sourcesyntaxhighlight lang="cfm">
<cf_addition first="1" second="2">
</syntaxhighlight>
</source>
 
CFX tags are custom tags which are developed using [[Java language|Java]] or [[C++]], and are prefixed with cfx_ just like cf_. Java and C++ tags are added to the CFML runtime environment using the CFML engine's administrator or by editing configuration files.
Line 190:
In the example below, component temperature.cfc has a method FtoC which converts temperature from Fahrenheit to Celsius. The test.cfm template invokes the method and converts 212 degrees Fahrenheit and outputs the result.
 
<sourcesyntaxhighlight lang="cfm">
<!--- temperature.cfc --->
<cfcomponent>
Line 205:
</cfinvoke>
<cfoutput>#fDegrees#&deg;F = #result#&deg;C</cfoutput> <br />
</syntaxhighlight>
</source>
 
CFCs may also be instantiated as objects. Assuming a CFC file called Person.cfc, an instance of this CFC would be instantiated as follows:
<sourcesyntaxhighlight lang="cfm">
<cfset person = CreateObject("component", "Person") /></sourcesyntaxhighlight>
 
CFCs also form the basis of the ability to create [[web services]] in CFML. A CFC is created in the usual way, and the attribute access="remote" added to any function within the CFC will make that function available to be called as a [[SOAP]]-based web service. The CFML engine auto-generates a [[Wsdl|WSDL]] and creates all the necessary stubs for the web service to function.