Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
PaulKD #1
Discussion: Attributes Vs Request variables and CustomTags
Two methods (that I am interested in) to pass variables into a custom tag are
:- 1. Setting a request variable 2. Passing a 'local' variable in the custom
tag To me there doesn't appear to be any advantage of one method over the
other (in terms of speed, memory, availability) - I would be interested to know
if other people have any thoughts on this.
PaulKD Guest
-
Any way to set attributes for server controls by referencing properties/methods/variables?
Hi all, I'm trying to find a declarative way to set server control attributes using the attribute="<%= SomeValue %>" syntax. This works fine... -
How do I access HTTP Request Object Header variables?
Disclaimer: I'm a Flex newbie so please pardon if I am missing something obvious. Scenario: The Flex URL is protected by enterprise SSO. After... -
CF7 with Request variables.
Hey, I've inherited a site that uses Request variables. The hosting company upgraded to CF7 and now the request variables are not working on... -
Calling CFCs contained in the CustomTags directory
If the CFCs are within the Custom Tags directory, you do not need the full path like you do when they are in your web root. You can just call them... -
Accessing page request / server variables in a class file.
Hi, Here's a question for you all. Under "classic" ASP any ASP page could have any number of #Include files. Using #Include files I could have... -
Adam Cameron #2
Re: Discussion: Attributes Vs Request variables and Custom Tags
It's considered "bad practice" to use global variables (in this case
request-scoped ones) in factored code, which would be one consideration.
On the other hand, as there's no way to declare what attributes a custom
tag ought to have, this makes this less relevant in CF, I guess.
From a self-coding documentation, it's easier to follow your variables if
you have
<cf_tag someattribute="some value" someotherattribute="another value">
Than if you sudenly start using some request-scoped variable in your tag
code.
If you WERE to use request-scoped variables to "pass in" values to a custom
tag, make sure you still validate their existence and validity before
diving in assuming they're OK. I'd also document the fact you're using
request-scoped variables in the header of the tag file, as it's not a
standard practice, so best to clarify what you're doing for others down the
track.
One thing I would *not* do is something like this (drawing a parallel to my
example above):
<cfset request.someattribute = "some value">
<cfset request.someotherattribute = "another value">
<cf_tag>
I would never create a request-scoped variable explicitly to save me
passing in an attribute. I would however contemplate using a
request-scoped variable which was truely a global variable to the request
(DSN, for argument's sake), in a read-only sense in the tag.
This raises another point. If I was to use a request-scoped variable in a
custom tag, I would only ever do so in a read-only sense. A custom tag
should never change the environment of its calling code ("never" is a
strong term, so maybe "almost never").
To this end, I would probably find myself doing this, to be honest:
<cf_tag dsn="#request.dsn#">
HTH
--
Adam
Adam Cameron Guest
-
PaulKD #3
Re: Discussion: Attributes Vs Request variables andCustom Tags
Adam, Thanks for your reply, The custom tag displays the page header, the
variable is created with cfsavecontent and is javascript code and is tested for
(against your recommendation) using cfif strucykeyexists(request,'js') - on the
plus side it is always read-only. I do pass other local variables correctly
through the custom tag but in this instance I currently feel inclined to leave
the javascript in request. My dsns will always be in application. More input
from other may dissuade me though. Regards, Paul.
PaulKD Guest



Reply With Quote

