Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Nov 06, 2009 Nov 06, 2009

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

1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 06, 2009 Nov 06, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 06, 2009 Nov 06, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2009 Nov 07, 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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 07, 2009 Nov 07, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2009 Nov 07, 2009

Ah, I see what you mean. I'll have another look.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2009 Nov 07, 2009

In light of your explanation, your code seems OK. What happens when you remove the extra " after ##qItem.date##?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2009 Nov 07, 2009

Use evaluate(de()) in place of evaluate(). I would do something like

<cfset column_detail = evaluate(de(ATTRIBUTES.column_detail))>

  #listGetAt(column_detail,i)#

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 07, 2009 Nov 07, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2009 Nov 07, 2009

Cheers! Good luck.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 10, 2009 Nov 10, 2009
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources