Skip to main content
Known Participant
November 6, 2009
Question

Trying to pass a string that needs to be evaluated in a custom tag.

  • November 6, 2009
  • 2 replies
  • 1375 views

I have a custom tag that runs a dynamic query and I'm trying to pass a string to it that has some variable names that is only relevant to that tag.

The attribute looks like this in the custom tag:

column_detail="

<a href=""page.cfm?category_id=##qItems.category_id##"" style=""cursor:hand;""><img src=""images/edit.gif"" /> ##qItems.category_title##</a>"

"

(qItems is the name of the query being run inside the tag)

and in the customtag itself I tried to call it like this

#Evaluate(ATTRIBUTES.column_detail)#

However, I get an error with the < in the anchor tag, because I guess it's trying to evaluate that as a mathmatical equation and falling short.

How do I properly pass that string to the tag and have the tag process those variables?

Thanks!

Paul

    This topic has been closed for replies.

    2 replies

    Participating Frequently
    November 11, 2009

    This should work for you. Also change the " (double quote) to a ' (single quote) on the start and the end of the cfset so it doent look confusing.

    evaluate(de(column_detail))

    d

    Sorry, just realised you already got an answer. lol

    Inspiring
    November 6, 2009

    First, instead of evaluate, try array notation.

    attributes["constants in quotes" & variables]

    It's faster and might even solve your problem.

    Second, what are you attempting to do when the problem occurs?

    Known Participant
    November 6, 2009

    I have a page that outputs a listing of data.  And I want to have a central template that handles the listing dynamically. I want to tell the template how many columns to display and I want to control how that data is displayed in each column.

    For instance, I could have a listing page that displays: Name, Date, Status.  And then I have another listing page that just has a Category and Status column.  I want to use a single template(tag) for this and I want to be able to control the display of the data in those columns, like if I wanted the Name data to be linked specifically for that listing page.

    So in my tag I wanted to do something like this

    <cfmodule template="mycustomtag.cfm"

         column_detail="<a href='link.cfm?id=##qItem.id##'>##qItem.name##</a>,##qItem.date##",##qItem.status##"

    >

    My template will loop through the column detail list to generate the data.  I [thought I] had to use Evaluate to evaluate those variable names on the page, and it works when I don't have any querky characters like <>.  My tag processes it something like this:

               <cfoutput query="qItems">

                   <cfloop from="1" to="#ListLen(ATTRIBUTES.column_headings)#" index="i">

                        <div id="column" style="width:#ListGetAt(ATTRIBUTES.column_widths, i)#px;">
                            #Evaluate(ListGetAt(ATTRIBUTES.column_detail,i))#
                        </div>
                    </cfloop>

              </cfoutput>

    Those variables (qItem.name) doesn't exist on the calling page so Im not sure what to do.

    Does that make sense?

    Thanks.

    BKBK
    Community Expert
    November 7, 2009

    <cfmodule template="mycustomtag.cfm"

         column_detail="<a href='link.cfm?id=##qItem.id##'>##qItem.name##</a>,##qItem.date##",##qItem.status##"

    >

    The extra " after ##qItem.date## seems to be a mistake. Remove it.

    Further, you could use # in place of ##, and abandon the evaluate function.  So, what do you get when you do something like this:

    <cfmodule template="mycustomtag.cfm"

         column_detail="<a href='link.cfm?id=#qItem.id#'>#qItem.name#</a>,#qItem.date#,#qItem.stat us#">

    <cfoutput query="qItems">

                   <cfloop from="1" to="#ListLen(ATTRIBUTES.column_headings)#" index="i">

                        <div id="column" style="width:#ListGetAt(ATTRIBUTES.column_widths, i)#px;">
                            #ListGetAt(ATTRIBUTES.column_detail,i)#
                        </div>
                    </cfloop>

              </cfoutput>