Question

passing variables into coldfusion (cfinclude) templates

Asked by: joehodge

Hi,

I am migrating a pl/sql web based system onto an Coldfusion server so have to re-write all my stored procedures into .cfm files.

In my current environment I use templates e.g.

PROCEDURE Pr_Main (p_procedure_name varchar2 default 3, p_div_count varchar2 default null) IS

BEGIN

        Pkg_StyleSheets.Pr_HeadTitle('KPI Front End');
         Pkg_StyleSheets.Pr_StyleSheet1;
         Pkg_StyleSheets.Pr_Javascript;
          Pkg_LOGIN.Pr_Menu(p_div_count);
      htp.bodyclose;

END;

and this creates the basis for all my pages,

I want to re-create this in coldfusion but read that:

..The model of an included page is that it is part of your page; it just resides in a separate file. The cfinclude tag cannot pass parameters to the included page, but the included page has access to all the variables on the page that includes it......

from:

http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000995.htm

Being a complete newbie to coldfusion how do I get round this?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-05-10 at 07:21:05ID21418934
Tags

cfinclude

,

coldfusion

,

variable

,

pass

Topics

ColdFusion Application Server

,

ColdFusion Studio

Participating Experts
3
Points
500
Comments
17

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. a .php cfincluded into .cfm
    Just curious is it possible. Never tried.
  2. <cfinclude...> question
    i am trying to include a page from another site (i.e www.site2.com) in my site (i.e www.site1.com) using the <cfinclude..> command. however it doesn't let me do this. is there a way around this? <cfinclude template="http://www.site2.com/contactus.cfm"> ...
  3. Pagination links in CFINCLUDE
    A few months ago I was assisted by member - ENTRANCE2002 with getting my next-n interface together. Everything was working ok until i realized a few days ago that the number of pages might grow to a larger number than the display limitations can handle. Now I need to figure...
  4. CFINCLUDE in a CFC
    I have a function on a CFC that I want to run and then executre a CFM page that will mail the results of that function to the user. I tried to insert a <cfinclude> but that does not seem to work at all. Can this be done?
  5. cfinclude in cfcomponent??
    OK, I want to create a a function in a cfc that calls a local varaible in a cfm. Can you look at my sample and provides some tips or advice. I'm trying to get better at these cfc because I hear V8 is removing cfm! YIKES! All I want to do is display text (ONE WORD) In Flash GR...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: pinaldavePosted on 2005-05-10 at 07:29:48ID: 13968738

CFC are something similar to cfinclude.
You can pass the params to that and receive the result back. Coldfusion component functions are object oriented methods of coldfusion.
http://www.macromedia.com/devnet/mx/coldfusion/cfcs.html
Regards,
---Pinal

 

by: Dain_AndersonPosted on 2005-05-10 at 07:32:29ID: 13968767

To get around this, you can use the CFMODULE tag (or a custom tag), which processes all data "outside" of the current template. Within the CFMODULE, you have access to the Caller and Attributes scopes; for former allows you to access variables in the calling template, whereas the latter allows you access to variables explicitly sent to CFMODULE:

<CFSET My_Variable1 = "123">
<CFMODULE TEMPLATE="foo.cfm" MY_VARIABLE2="bar">

...in foo.cfm, you have access to:

#Attributes.My_Variable1#
#Caller.My_Variable2#

You can also use CFCs -- check out more about CFMODULE, custom tags,  and CFCs (ColdFusion components) in the LiveDocs.

HTH,

-Dain

 

by: Dain_AndersonPosted on 2005-05-10 at 07:33:18ID: 13968776

Oops, that should read:

#Attributes.My_Variable2#
#Caller.My_Variable1#

 

by: pinaldavePosted on 2005-05-10 at 07:35:16ID: 13968790

Dain has good suggestion.
If you are confused what is different between Custom Tag/module and CFC .
Here is good article for you : http://www.macromedia.com/devnet/mx/coldfusion/articles/custom_cf_tag.html
Regards,
---Pinal

 

by: joehodgePosted on 2005-05-10 at 07:36:03ID: 13968803

wow! thanks for the quick responses.

I will plod my way through them so I might not respond straight away.

thanks

 

by: trailblazzyr55Posted on 2005-05-10 at 10:48:23ID: 13970821

you can use the <cfinclude template="yourpage.cfm"> to call pages to yours. I'm not sure where a custom tag or cfmodule would help? unless you have apps you want to include in your page?

if you have say a calendar popup app...

use cfmodule to call and pass parameters or cf_tagName and used much the same...

or if you have properties set on certain pages and want to include them, this also includes queries and styles,

use <cfinclude template="YourTemplateName.cfm">

but you mentioned you have templates, I think cfinclude would work best... I may have missed something though ;0)

~trail

 

by: trailblazzyr55Posted on 2005-05-10 at 10:55:57ID: 13970886

one thing to may sure of, if there are required for the template, they have to be set on the page, of called before the template that requires them is called... example:

<cfset myvarr = NameOfHouse>
<cfinclude template="qry_houses_template.cfm">

<cfoutput query="houses_names_sp">
#currentrow# - #house_name#
</cfoutput>

the qry_houses_template.cfm would contain something like this....

-------this calls a stored procedure--------------
<cfquery name="houses_names_sp" datasource="#DSN#">
      { call dbo.houses_names_sp ('#myvarr#') }
</cfquery>

or

-------standard query--------------------
<cfquery name="houses_names_sp" datasource="#DSN#">
   SELECT * FROM YourTable WHERE HouseName = '#myvarr#'
</cfquery>

so the variable would have to be set prior to calling that page, or it will give an error...

~trail

 

by: joehodgePosted on 2005-05-11 at 01:17:34ID: 13975822

Hi,

I used the cfmodule tag:

----------Home.cfm-----------------
<!-- header starts here -->
      <cfmodule template = "Header.cfm" title = "Home Page">
      </head>
<!-- header ends here -->

<!-- content starts here -->
      <body>


----------Header.cfm-----------------


<cfset title = attributes.title>

<cfoutput>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
      <title>#title#</title>
      
<link rel="stylesheet" type="text/css" href="./stylesheet/OTIF.css">
      
<SCRIPT language="Javascript">
                  var password;
                  var username;

etc...

thanks for all your help!

 

by: trailblazzyr55Posted on 2005-05-11 at 09:42:08ID: 13979692

just to let you know, most would code what you did in a cftemplate, and set their header attribute in their application.cfm, what you did seems kind of backwards and not a proper use of cfmodule..

it's like driving a big rig to and from work in the morning, it'd work but why not just use a car???? much easier huh?? You set your header title in your application.cfm build a thousand pages and all you have to do is change that one variable. You use cfmodule you have to change it on every other page where you call it. Seems like a lot of extra hastle to me, which is why I recommended the cfinclude. One I thought yuo were doing just this with it, and two you really don't need a cfmodule because it's not a function or app your running on your page, it's just a header with a dynamic title...

Anyway, it's your page and your code, I personally haven't seen it done that way anywhere,a nd wouldn't use that method myself, our site has well over a thousand pages and it would be such a hastle doing that.

best regards,
~trail

 

by: Dain_AndersonPosted on 2005-05-11 at 10:13:21ID: 13979948

I agree with trailblazzyr55 in that unless your title dynamically changes page-by-page, you would want to set it at a higher level (i.e., Application.cfm); however, if your page title is dynamic, you could certainly use CFMODULE, as it would make sense in this situation.

-Dain

 

by: trailblazzyr55Posted on 2005-05-11 at 11:28:02ID: 13980595

I guess I've got away from static page creation...

you can certainly have different page titles for different pages with cfinclude.. here's an example of what I'm saying...

[Folders]

wwwroot...
application.cfm
index.cfm
[Site Loc 1]
[Site Loc 2]
[Site Loc 3]
[Javascript]
[Queries]
[SysFunc]

..[Site Loc 1]
  index.cfm
  otherfiles.cfm..

..[Site Loc 2]
  index.cfm
  otherfiles.cfm

.. and so on...

Now you set a default header title in your root application.cfm ie: <cfparam name="title" default="MyTitle">

this would be your site hompage url: http://www.yourdomain.com  right????

this uses the root index.cfm

NOW:

you have subfolders in you wwwroot directory (site pages)... following???

in those folders you can have a file called header.cfm and title would be ofcourse #title# right??

your index page for that site/folder/part of site would set the title variable which over-rides the application default...

so each page in that folder which calls the correct header.cfm template uses that specific title, you want to change the title at a different time, easy... edit the index.cfm for that folder...

each page in that folder would use cfinclude to call the header... there's no need for cfmodule anywhere...

so it puzzles me why you'd want to use cfmodule to call a header, yes it's possible... but why do it?

Anyway, not to cause a big discussion or anything, that's just my way, others have different ways maybe for easier or harder, just the amount of time I guess you want to spend editing at a later point I guess...

questions been answered so I guess they're happy with what they got ;o)

Dain_Anderson,

just out of curiosity... why would using cfmodule make sense in this situation? or better sense than cfinclude? Not partial to cfinclude or anything I'm just curious ;o)

~trail







 

by: Dain_AndersonPosted on 2005-05-11 at 11:39:16ID: 13980705

Trail,

If you're just using CFMODULE for a title, I would tend to agree that it's overkill, even if the title is dynamic. One situation that I was confronted with was for an intranet application I built a while ago for a bank that essentially required a "header" file to be on every page that was dynamically built. The header file ran a routine that created on-the-fly inner-page title graphics (using Java). If we used CFINCLUDE to do this, the page would wait until the graphic loaded, while doing it with CFMODULE, we were able to process the rest of the page while the external CFMODULE routine processed the dynamic graphic. Granted, each situation needs to be evaluated as to the best method, but I assure you in some cases (such as the one I described) it could easily be necessary.

Now, as for HTML titles, etc, I personally use a "wrapper" for all layouts, etc. so that I don't have to run any includes or modules for most applications. But I think for the scope of this question, that gets to be a little complicated.

-Dain

 

by: trailblazzyr55Posted on 2005-05-11 at 12:02:06ID: 13980930

Yep you're right, I could definitely see where having a function to display dynamic page titles based on criteria would require a cfmodule.
I don't think joehodge was using Java or any functions, he just wanted to display a page title by means of templates in the header... from what I read anyway...

I think you're right a wrapper would do as well. but yes i think is beyond the scope of the question ;o)

~trail

 

by: joehodgePosted on 2005-05-12 at 02:19:17ID: 13984510

Hi all,

it seems like I've kicked off a bit of a discussion!

The header 'title' attribute was just to get things going, I will need to pass in all sorts of variables when I use my menu template. I was also looking to completley seperate the logic e.g. SQL selects etc from the HTML code in other pages, so that it should(?) be easier to maintain.

I will probably change the code now I know about application.cfm but I just wanted to get a working example of passing parameters through templates.

I have already encountered a few issues with using cfmodule so I'm sure you'll here from me again!

 

by: joehodgePosted on 2005-05-12 at 02:26:22ID: 13984527

Also as our site is an intranet, every page has its own unique title so if every page contained an identical header e.g.

<cfset title = attributes.title>

<cfoutput>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
     <title>#title#</title>
     
<link rel="stylesheet" type="text/css" href="./stylesheet/OTIF.css">
  <script src="/scripts/main.js" type="text/javascript"></script>

</head>

etc

Is it better practice to have this in a template or should I be putting all this into application.cfm or 'wrappers'?

 

by: Dain_AndersonPosted on 2005-05-12 at 05:52:37ID: 13985642

I'd prefer a wrapper here, as commonly used in the FuseBox methodology, or perhaps an "output" CFC method. For SQL, I _personally_ encapsulate all my queries, sorted by functionality, in CFCs. I store heavily-used, common CFCs in Session variables, then stransfer them to the Request scope using StructAppend() (surrounded in a CFLOCK). If you're not familiar with CFCs, I'd highly recommend you take a look. I don't even use Application.cfm for common variables like the datasource name, paths, etc. -- I use an initialization CFC to store this data, which in turn accesses an XML file for all settings. This allows me to "port" the site easily to many different clients without having to change _any_ code at all; rather, I simply alter the _manifest.xml file for each client.

To give you an idea of what one of my Application.cfm files looks like, I've attached it here:

<CFSILENT>
<!------------------------------------------------------------
      No cache headers --->
<CFHEADER NAME="Expires"          VALUE="Tue, 01 Jan 1985 00:00:01 GMT">
<CFHEADER NAME="Pragma"        VALUE="no-cache">
<CFHEADER NAME="cache-control"       VALUE="no-cache, no-store, must-revalidate">

<!------------------------------------------------------------
      Application/Session Control Variables --->
<CFPARAM NAME="Request.SERVER_PORT"   DEFAULT="80">
<CFPARAM NAME="Request.SessionTimeout"       DEFAULT="#CreateTimeSpan(0,0,59,0)#">
<CFPARAM NAME="Request.AppRefresh"         DEFAULT="">
<CFPARAM NAME="Request.FailoverEmail"         DEFAULT="xxxxx@xxxx.com">
<CFPARAM NAME="Request.Debug"                 DEFAULT="No">

<!------------------------------------------------------------
      Disable/Enable debugging --->
<CFSETTING SHOWDEBUGOUTPUT="#Request.Debug#">

<!--- For installations with different SSL host, use a unified app name --->
<CFPARAM NAME="Request.ApplicationName" DEFAULT="SA_#GetToken(CGI.SERVER_NAME, 1, ".")#">

<!------------------------------------------------------------
      We use JSESSIONIDs, NOT CFID/CFTOKEN --->
<CFIF IsDefined("Cookie.CFID")>
      <CFCOOKIE NAME="CFID" VALUE="#CFID#" EXPIRES="NOW">
</CFIF>
<CFIF IsDefined("Cookie.CFTOKEN")>
      <CFCOOKIE NAME="CFTOKEN" VALUE="#CFTOKEN#" EXPIRES="NOW">
</CFIF>

<!------------------------------------------------------------
      Instantiate Application for the Specific Client --->
<CFAPPLICATION
      NAME="#Request.ApplicationName#"
      CLIENTMANAGEMENT="No"
      SESSIONMANAGEMENT="Yes"
      SETCLIENTCOOKIES="No"
      SESSIONTIMEOUT="#Request.SessionTimeout#"
      APPLICATIONTIMEOUT="#CreateTimeSpan(0,12,0,0)#">

<!------------------------------------------------------------
      First Pass: Make sure this account exists
      Get Account settings and server-specific vars
      (stored in Application) --->
<CFLOCK SCOPE="APPLICATION" TYPE="EXCLUSIVE" THROWONTIMEOUT="Yes" TIMEOUT="20">
       <CFIF IsDefined("Application.Started")>
             <CFSET StructAppend(Request, Application)>
      <CFELSE>
            <CFINVOKE COMPONENT="components.accounts.cfc_AccountSettings" METHOD="getAccountInformation" RETURNVARIABLE="IsValid">
            <!------------------------------------------------------------
                  Ensure the account exists (true) --->
            <CFIF IsValid>
                  <CFSET StructAppend(Request, Application)>
            <!------------------------------------------------------------
                  Account doesn't exist --->
            <CFELSE>
                  <CFMODULE TEMPLATE="security/dsp_accessDenied.cfm" ErrUnencrypted="ACC-1001">
                  <CFABORT>
            </CFIF>            
      </CFIF>
</CFLOCK>

<!------------------------------------------------------------
      Browser Detection --->
<CFLOCK SCOPE="SESSION" TYPE="EXCLUSIVE" TIMEOUT="10" THROWONTIMEOUT="Yes">
      <CFIF NOT IsDefined("Session.Browser")>
            <CFINVOKE COMPONENT="components.cfc_BrowserDetection" METHOD="getBrowser" RETURNVARIABLE="Session.Browser">
      <CFELSE>
            <CFSET StructAppend(Request, Session)>
      </CFIF>                        
</CFLOCK>

<!------------------------------------------------------------
       UTF-8 Encoding --->
<CFSET SetEncoding("FORM", "UTF-8")>
<CFSET SetEncoding("URL", "UTF-8")>

</CFSILENT>

-Dain

 

by: joehodgePosted on 2005-05-12 at 06:40:17ID: 13986217


thanks for the expert advice!,

I will open another thread with the subject of the above so your time is rewarded.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...