Solved

cfincludes and start tags and end tags

Posted on 2004-09-22
7
268 Views
Last Modified: 2013-12-24
I have a page.

It has 2 cfincludes.

I want to include a start tag in 1 include and the end tag in the other include.

For instance,

the first include might be

<cfoutput>#Now()#

and the other include would be

</cfoutput>

I would expect this to work but it does not.

It errors saying it cannot find the end tag.  If I used </cfoutput> in the main page instead of the include it says it cannot find the start tag.

It appears when it is checking to make sure you have start and end tags that it only is looking in each include statement for both the start and end tags.  In addition, the main page also appears to be looking for both the start and end tag.

Is there anyway I can seperate the start and end tages in different includes and get the page not to error.

I tried putting the < in the main file and then the first include looked like this

cfoutput>#Now()#

and then I put another < in the main file and the 2nd include looked like this
/cfoutput>

This did not error however the page just displayed #Now()#.  I was suprised by this.  What happenned to the <cfoutput> and </cfoutput>?

I really want to do this.  

Thanks, Franz
0
Comment
Question by:FranzRinkleff
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 9

Expert Comment

by:shooksm
ID: 12127911
"I really want to do this."

No you don't.  It makes the maintenance for the poor schlub who has to clean up your code after you leave a nightmare.  He gets to play follow the include files until he finds where you put all the end tags.  Don't do this.  There is no reason you can give me that you have to have functionality like this.

But the reason why it doesn't work is CFINCLUDE does not work like SSI where the included files are assembled before passing to the scripting engine.  Each included file is treated as a seperate CFM and parsed before running the code.  The advantages of this way of treating each include as a physically seperate file allows you to do dynamic includes where you can change the template property of an include on the fly before the page is physically to be processed.
0
 
LVL 1

Author Comment

by:FranzRinkleff
ID: 12128345
I still really want to do this.  

It is actually for ease of maintenance that I want to do this.

We have a custom tag with a lot of attributes.  Currently, we ALWAYS use the same values for the attributes in the start tag.   I figured if we used a CFINCLUDE we could define the tag once with all of the attributes and not have to cut and paste the entire tag everytime we want to use it.  In addition, in the future if we decide that we need to change one of the attributes we can just change them once in the cfinclude instead of finding every page which has used this tag and changing the attributes on each page.  I could see us eventually having 3 or 4 combinations of the attributes however even then I think it would be better to have 3 or 4 cfincludes.

However based on your answer I don't think I will be able to do it.

Do you have any ideas that would help me since cfinclude will not work?
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 12128492
Its not possible, the end tag needs to be in the same page..
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 17

Expert Comment

by:Tacobell777
ID: 12128499
If there is something you always want to include, then put it in your application.cfm file..
0
 
LVL 9

Accepted Solution

by:
shooksm earned 250 total points
ID: 12129498
So can't the call to the custom tag be in its own include?

Personally, I would set default values for every attribute using CFPARAM in the custom tag.  Make the default values what you are most likely to use on a majority of the pages, then on the pages where one or more attributes need to be set a different value, you just pass them in.  If you want to change an attribute for every page, it is one edit to the custom tag with the exception of the pages that overide the default value by passing in an attribute.
0
 
LVL 1

Author Comment

by:FranzRinkleff
ID: 12130285
The custom tag is used to call another program which creates another file.

It is the code in between the custom tags which appears in the created file.

Since the code in between the custom tags is different on every page it cannot be part of an include statement.

I was hoping to avoid having to put the custom start tags with all of their attributes in every file since as I stated before the attributes will probably always be the same or just a few variations which means I would only need a few different includes

If we ever wanted to change the attributes I also did not want to have to modify every file which has the custom tags.

Your idea using CFPARAM is probably as good as I am going to get.  I would still have to cut and paste the start tag but at least I would be able to change the attributes easily if I ever needed to do it.  

Thanks, Franz
0
 
LVL 9

Expert Comment

by:Jerry_Pang
ID: 12130298
either insert the tags inside the include page or separate them.

1st
your include.cfm
----
<cfoutput>
you include page here
</cfoutput>

that way you only have to call the include statement

or
2nd
<cfoutput>
<include here>
<include2 here>
</cfoutput>

Doing what you wanted makes the debug a lot troublesome.

i do suggest redesigning your code.
but still the end tag must be on the same page.
does your includes only for cfoutput? or for all coldfusion tags?
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question