Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

coldfusion ignore undefined variables

Tags:

coldfusion

if I use

<cfoutput>#somevariable#</cfoutput>

and somevariable is not defined I get an error, how can I prevent the error from occourring? is there a simple way of implementing a conditional that doesn't require a bunch of extra lines?

like image 660
Daniel Avatar asked Dec 17 '22 18:12

Daniel


1 Answers

<cfparam name="somevariable" default="" />

If you're on cf 9 you can use a ternary operation, but cfparam is more 'best practicey'.

#isDefined("somevariable") ? somevariable : 'default string'#
like image 155
Todd Sharp Avatar answered Dec 19 '22 06:12

Todd Sharp