Dynamically Build a Tag

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

  1. #1

    Default Dynamically Build a Tag

    I want to dynamically build a tag using conditionals for example;

    <cfmail <cfif condition EQ 1>CC="#myvar#" <cfelse> BCC=#myvar#</cfif> ....>

    Any idea how to do this would be helpful since I get this error and can't
    seem to figure what the work around is:

    " Invalid token found on line 229 at position 4. ColdFusion was looking at the
    following text:
    <
    Invalid expression element. The usual cause of this error is a misspelling in
    the expression text."


    grndvl1 Guest

  2. Similar Questions and Discussions

    1. How to build populate datagrids dynamically
      The data returned from the server in my flex app is one-dimensional: A 1 xyz A 2 abc A 3 pqr I want to put this data into a datagrid so...
    2. Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created)
      Ok here's my scenario. I have a Custom Composite Server Control (CCSC) consisting of a TextBox, Button & Panel. (And some other code - which I...
    3. dynamically build sql based on text in textbox and dropdownbox
      I have a web form that contains textboxes for first name and last name. I also have a dropdown list that contains companies. I would like the...
    4. Best way to build a form dynamically
      Hello Control Builders:: Part of the form that I am designing has to be built dynamically. I ultimately want to create a set of controls that are...
    5. Dynamically build RangeValidation control for text box
      Hello I am building a textbox control dynamically. I need to check if the value entered in the text box has a specified minimum number of...
  3. #2

    Default Re: Dynamically Build a Tag

    AFAIK, you can't embed CF tags within another tag in order to dynamically
    select which attributes to set.

    Using your condition, you could set values for the CC and BCC attributes and
    make one of them blank depending on the condition. I tested the attached code
    and it seems to work fine.

    -Paul



    <CFIF condition EQ 1>
    <CFSET ccstring = myvar>
    <CFSET bccstring = "">
    <CFELSE>
    <CFSET ccstring = "">
    <CFSET bccstring = myvar>
    </CFIF>

    <CFMAIL TO="#tostring#" FROM="mymail@myserver.com" CC="#ccstring#"
    BCC="#bccstring#" SUBJECT="Test">
    Here's a mail test.
    </CFMAIL>

    dempster Guest

  4. #3

    Default Re: Dynamically Build a Tag

    Problem is the custom tag I am using errors out when one of the attributes is "". Anyway isn't there a way to do it with Evaluate()??
    grndvl1 Guest

  5. #4

    Default Re: Dynamically Build a Tag

    How about... in your custom tag, use a switch or other conditional statement to invoke different "styles" of <CFmail> depending on the conditions... ?
    mate of the state Guest

  6. #5

    Default Re: Dynamically Build a Tag

    Sorry CFMAIL is only the example I was using not the actual tag that is causing
    me pains, just used this to illustrate what I was talking about. Anyway no way
    to code the custom tag myself since it is encoded. Also too many conditions
    to cleanly do it. Might build the a string then use Evaluate on it to render
    the tag, never tried that before....hmmm.

    grndvl1 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