Checking a variable's existence in Coldfusion

I am trying to add navigation to my mini CMS, I want to display only 7 stories at a time, then present a link for more. I was going to do this by passing the variable #offset# through the query string, and then adding it into my CFQUERY tag as STARTROW.

Here is my dilemma.

How can I check to see if offset is not set, and if it isn’t how can I set it to zero? I know how to do this in php and asp, but I don’t understand how coldfusion handles control structures.

if (!isset($offset)) { $offset=0 }

Thats how I do it in php, how can I duplicate that in CFML?

Also how can I add something to a variable? (i.e. #offset#+7) Then can I stick it into my query string as the new offset.

<a href="index.cfm?offset=<CFOUTPUT>#offset#+7</CFOUTPUT>">More Stories</a>

Like that?

Finally, is there anyway I can create a function to do this? like I’ve done in php or asp? that I can resuse?

You can use the IsDefined() function to check for the presence of a variable…

<CFIF IsDefined(url.offset)></CFIF>

Hope that helps.


you can also assign defaults with cfparam

<cfparam name="url.offset" default="something">

if the variable doesn’t exist, it will be created and asigned the default.