Override Coldfusion Built In Tag

226 views
Skip to first unread message

Arpan Paul

unread,
Sep 3, 2014, 11:07:21 AM9/3/14
to ra...@googlegroups.com
Hello,
We are moving from coldfusion 9 to railo and amazon s3. I saw this cool feature in some old posts about overriding built-in functions. However I am unable to get it to work.
As far as I understand from the posts, if I want to override a function or a tag, I write a UDF and put it in the railo context lib/function or tag appropriately and restart railo and it should get overridden.

The tag I am interested in overriding/wrapping is cfinclude.
I want to change the template path before passing it to the builtin cfinclude. Basically, I want the cfinclude to check if a file is in S3, if it is not, then look for it in the local filesystem of the server, and then include it.

So I have this function to test. I have tried with naming the file and functionname cfinclude, and include - neither work.
I put it in /opt/railo/lib/railo-server/context/library/tag/ and /opt/railo/lib/railo-server/context/library/function/

<cffunction name="Include" output="yes" returntype="any" hint="Custom cfinclude in /opt/railo/lib/railo-server/context/library/tag/Include.cfm.">
<cfargument name="template" type="string" required="yes" hint="Template to include"> 
hello                                                                             
<cfinclude attributeCollection="#arguments#">                                  
</cffunction> 

I restarted railo multiple times and tried different variations and naming, but this is not called.

How can I get this to work? Overriding built in stuff opens up so many new possibilities for us, we would rather not go in our code and update over 1000 places we use cfinclude.

Thank you
Arpan

Michael Offner

unread,
Sep 3, 2014, 1:12:27 PM9/3/14
to ra...@googlegroups.com
Railo use this feature also for some of it's own build in tags, for example the tag and function dump/writedump.
to test if you are in the right place, rename for example writedump.cfc to d.cfm, then rename the function inside to "d" as well and restart railo, then you should be able to call d(now());
if this is not working you are in the wrong place.

Micha





--
Did you find this reply useful? Help the Railo community and add it to the Railo Server wiki at https://github.com/getrailo/railo/wiki
---
You received this message because you are subscribed to the Google Groups "Railo" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/railo/58e8dddb-131e-4dac-a2fb-10350492a097%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
/micha

Michael Offner CTO Railo Technologies GmbH

Arpan Paul

unread,
Sep 5, 2014, 5:50:56 PM9/5/14
to ra...@googlegroups.com
Hello,

Thanks for that pointer, the cfinclude override is working now.
However, I think overriding cfinclude has broken the default way it used to work, so we don't see the variables defined outside of it.

For example:

<cfset a = "b">
<cfinclude template="c.cfm"> <<<<<------------- <cfoutput>#b#</cfoutput>
(No such variable b)


The original coldfusion cfinclude tag, it would see the variable inside the cfincluded template. 
How can I add this functionality back into the new overridden cfinclude tag?

Thank you
Arpan

Michael Offner

unread,
Sep 6, 2014, 3:28:38 PM9/6/14
to ra...@googlegroups.com
This depends on how you have implemented, this tag.
There are 3 ways, to do so.

1. Cfm based custom tag
In that case you read and write data from the outside world with help of the "caller" scope like always with classic custom tags.

2. Cfc based custom tags
In that case it is not that easy, see for example the attribute "eval" from the tag "dump"

3. Java based custom tag
This tag does not add a new layer at all.

If you need that cfinclude works on a external resource like s3, you don't have to rewrite cfinclude for that, there is a easier way to do so. Simply add a mapping "/" in the admin that point to your s3 resource. We can also help you write a java based include replacement ...

Micha
--
Did you find this reply useful? Help the Railo community and add it to the Railo Server wiki at https://github.com/getrailo/railo/wiki
---
You received this message because you are subscribed to the Google Groups "Railo" group.

For more options, visit https://groups.google.com/d/optout.

Arpan Paul

unread,
Sep 6, 2014, 5:51:51 PM9/6/14
to ra...@googlegroups.com
Hello.
I implemented it via a custom tag. Something like this
<cfif thisTag.executionMode IS "start">
 
<cfparam name="attributes.template" default="">
 
<cfinclude template="#attributes.template#"/>
</cfif>

but that would mean that existing code which is being cfincluded will need to change the way it is looking for variables right? That is something I am trying to avoid, its just way too many files. Is there something I can do in the custom tag, so that the included files can see the variables naturally as they did before overriding the cfinclude tag?

Thank you
Arpan

Michael Offner

unread,
Sep 7, 2014, 3:46:01 AM9/7/14
to ra...@googlegroups.com

I have not tested but I do not know out of my mind, but something like this maybe works
<cfif thisTag.executionMode IS "start">
<cfloop struct="#caller#" index="k" item="v">
<cfset variables[k]=v>
</cfloop>

 <cfparam name="attributes.template" default="">
 <cfinclude template="#attributes.template#"/>
<cfloop struct="#variables#" index="k" item="v">
<cfset caller[k]=v>
</cfloop>
</cfif>

Micha

--
Did you find this reply useful? Help the Railo community and add it to the Railo Server wiki at https://github.com/getrailo/railo/wiki
---
You received this message because you are subscribed to the Google Groups "Railo" group.

For more options, visit https://groups.google.com/d/optout.

Arpan Paul

unread,
Sep 8, 2014, 12:05:40 PM9/8/14
to ra...@googlegroups.com
That worked, thanks !
Reply all
Reply to author
Forward
0 new messages