Beginner DTML question: dereferencing a variable
I know the answer to this must be pretty simple, but I can't work it out from any of the docs and it's driving me nuts. I have a variable that contains a username: <!--#call "REQUEST.set('theusername',AUTHENTICATED_USER.getUserName() )"--> I want to check if a folder of that name already exists under the current folder, so I can decide to create it or not. Intuitively, I first tried: <!--#if "theusername"--> <H3>FOLDER EXISTS</H3> <!--#else--> <H3>FOLDER DOES NOT EXIST</H3> <!--#/if--> But all this seems to detect is if the variable is set or not. :( Other variations are getting me nowhere ... what's missing? -- Martin Dougiamas
Martin Dougiamas wrote:
I want to check if a folder of that name already exists under the current folder, so I can decide to create it or not.
Intuitively, I first tried:
<!--#if "theusername"--> <H3>FOLDER EXISTS</H3> <!--#else--> <H3>FOLDER DOES NOT EXIST</H3> <!--#/if-->
I seem to found a solution myself. This seems to work: <!--#if "_.has_key(theusername)"--> <H3>FOLDER <!--#var "theusername"--> EXISTS</H3> <!--#else--> <H3>FOLDER <!--#var "theusername"--> DOES NOT EXIST</H3> <!--#/if--> ...as long as there's not a object with that name UP the hierarchy, I suppose. If there's a cleaner way to do this I'd still like to know it. Cheers! Martin
participants (2)
-
Martin Dougiamas -
Martin Dougiamas