Re: [WebDNA] How to use [function]
This WebDNA talk-list message is from 2012
It keeps the original formatting.
numero = 108659
interpreted = N
texte = LawrenceI tend to use functions where I have a complicated bit of logic (either =within or without a search context), more often when I would prefer no =white space in between linesyou can do it like this[hideif [myVar]=3D1][!] [/!][text]myNewVar=3D100[/text][!][/!][/hideif]is the same as this[function name=3DgenerateNewVar] [hideif [myVar]=3D1] [text scope=3Dglobal]myNewVar=3D100[/text] [/hideif][return][/return][/function][generateNewVar]I find the 2nd one easier to read.It is especially handy when generating XML, I find.Alternatively I would use it for text translation - [translateMyText =textToTranslate=3D[myDateVar]&language=3Dfrench] - and MySQL functions - =somehow it's easier to print out [findMyRecords myVar=3D1] than do all =the steps necessary for=20Normally a repeated bit of logic where the output is always in the same =format, but small input elements change is where I would use it most. In =the example you have given, I would almost always write this as inline =code. If, however, you wanted to have a find function that always =printed the results out in the same manner, you could do the following:[function name=3DgetResults] [search db=3D[whichDb].db&&neSKUdata=3D[blank]] [founditems] [return]
[SKU]-[name]
[/return] [/founditems] [showif [numfound]=3D0] [return]Nothing to see here[/return] [/showif] [/search][/function]and on your page
[getResults whichDb=3DmyDb]
and again somewhere else
[getResults whichDb=3DanotherDb]
Hope this helps....TC> Toby,=20> I'm trying to understand in which case I should use the [function] or =not.> Your example is clear, It looks like it would be nice to have all the =webdna code in separate files, and have only the result called in the =page, that would make page codes clear.> for the break/stop the documentation says :> "'The [return] context does NOT 'break out' of a function call, so it =is possible to use one or more [return] contexts to 'tailor' the =functions output. ">=20> Kenneth,=20> how would you use an array with this kind of search function?>=20> Thanks> Lawrence
Associated Messages, from the most recent to the oldest:
LawrenceI tend to use functions where I have a complicated bit of logic (either =within or without a search context), more often when I would prefer no =white space in between linesyou can do it like this[hideif [myVar]=3D1]
[!] [/!]
[text]myNewVar=3D100[/text]
[!][/!][/hideif]is the same as this[function name=3DgenerateNewVar] [hideif [myVar]=3D1] [text scope=3Dglobal]myNewVar=3D100[/text] [/hideif]
[return][/return][/function][generateNewVar]I find the 2nd one easier to read.It is especially handy when generating XML, I find.Alternatively I would use it for text translation - [translateMyText =textToTranslate=3D[myDateVar]&language=3Dfrench] - and MySQL functions - =somehow it's easier to print out [findMyRecords myVar=3D1] than do all =the steps necessary for=20Normally a repeated bit of logic where the output is always in the same =format, but small input elements change is where I would use it most. In =the example you have given, I would almost always write this as inline =code. If, however, you wanted to have a find function that always =printed the results out in the same manner, you could do the following:[function name=3DgetResults] [search db=3D[whichDb].db&&neSKUdata=3D[blank]]
[founditems] [return][SKU]-[name]
[/return] [/founditems] [showif [numfound]=3D0]
[return]Nothing to see here[/return] [/showif] [/search][/function]and on your page
[getResults whichDb=3DmyDb]
and again somewhere else
[getResults whichDb=3DanotherDb]
Hope this helps....TC> Toby,=20> I'm trying to understand in which case I should use the
[function] or =not.> Your example is clear, It looks like it would be nice to have all the =webdna code in separate files, and have only the result called in the =page, that would make page codes clear.> for the break/stop the documentation says :> "'The
[return] context does NOT 'break out' of a function call, so it =is possible to use one or more
[return] contexts to 'tailor' the =functions output. ">=20> Kenneth,=20> how would you use an array with this kind of search function?>=20> Thanks> Lawrence
Toby Cox
DOWNLOAD WEBDNA NOW!
Top Articles:
Talk List
The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...
Related Readings:
WC2b15 - [HTMLx]...[/HTMLx] problems (1997)
OT: Way off-topic: Qmail and Linux (2003)
WebCat2: Master Counter snippet (1997)
IIS4b2 and WebCatalog b19 (1997)
[showif] / [hideif] (1997)
Running 2 two WebCatalog.acgi's (1996)
ImageMagick Commands? (2003)
turning every 5th line red (1999)
can WC render sites out? (1997)
Design Help Needed (1998)
Security Tip (1996)
[OT] Yahoo! Front Page (2002)
WC on Mac OS X or Mac OS X Server 2.x (2001)
Updating Prices in Online Database (1999)
Reload adding to cart (2001)
more cookie crumbling (1999)
Groups doesn't work (1997)
[Off] Netscape Display Problem (1998)
Running 2 two WebCatalog.acgi's (1996)
Upload and WebCat (1998)