Discussion: Attributes Vs Request variables and CustomTags

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139