Tuesday, 9 October 2007

Load pages using URL variables with Coldfusion cfinclude and cfif tag

The same approach used in all previous post can be used with other server-side languages, for example Coldfusion. This post show how to load pages using Coldfusion URL variables with <cfinclude> and <cfif> tag.



A coldfusion URL Variable is defined simply with this dotted code (URL + . + 'varname'):

URL.varname


Copy and paste this code inside the #main section in index.cfm file (see this post to examine the page structure):

<!-- If is defined URL variable 'aboutme' -->
<cfif isDefined('URL.aboutme')>
<!-- include page 'about me' -->
<cfinclude template="include/in-aboutme.cfm">
<!-- else if is defined URL variable 'interests' -->
<cfelseif isDefiend('URL.interests')>
<!-- include page 'interests' -->
<cfinclude template="include/in-interests.cfm">
<cfelse>
<!-- in all other cases include the home page -->
<cfinclude template="include/in-home.cfm">
</cfif>


The result is the same obtained with PHP in the previous post.

No comments:

Post a Comment