Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
<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>
Copy link to clipboard
Copied
Thanks, but that doesn't work out.
I have to ## because those variables don't exist on the page that calls that custom tag.
And if I need coldfusion to process the values of that attribute "column_detail" before it outputs the data. Otherwise I just get the output "#qItem.name#" instead of the value of that variable.
Copy link to clipboard
Copied
Ah, I see what you mean. I'll have another look.
Copy link to clipboard
Copied
In light of your explanation, your code seems OK. What happens when you remove the extra " after ##qItem.date##?
Copy link to clipboard
Copied
Use evaluate(de()) in place of evaluate(). I would do something like
<cfset column_detail = evaluate(de(ATTRIBUTES.column_detail))>
#listGetAt(column_detail,i)#
Copy link to clipboard
Copied
BINGO!
I tried to use DE in some other way before but it didn't work for me. Yours did the trick. The custom tag now calls the variable like this:
#Evaluate(DE(ListGetAt(ATTRIBUTES.column_details,i)))#
Which gets the job done!! Yay!
I appreciate the help!
Paul
Copy link to clipboard
Copied
Cheers! Good luck.
Copy link to clipboard
Copied
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