We help IT Professionals succeed at work.

Generating CFM pages dynamically

415 Views
Last Modified: 2013-12-24
i am doing something very wired here can someone guide in proper way:

i am trying to generate the page dynamically based on the countries list. like if country is iceland, a page with iceland.cfm will be generated and it will be filled with the content that i have on my cfinclude page:

here is what i am trying to do.

<cfinvoke component="#request.cfcPath#.tools" method="addnewdeal" argumentcollection="#form#"/>
      <cfset templatePage = 'makepages.cfm'>
      <cfinclude template="#templatePage#">
      <cffile action="write" file="#request.absolutePath##form.countryURL#.cfm" output="#topbar#">
MAKEPAGES.CFM full code:
 
request.abosultepath is the path which points to the files properly.
 
<cfsavecontent variable="topbar">
<cfoutput>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<cfinclude template="#request.absolutePath#meta.cfm">
<link rel="stylesheet" type="text/css" href="#request.absolutePath#style.cfm" media="screen" />
<script language="javascript1.2" src="#request.absolutePath#other/flashobject.js" type="text/javascript"></script>
<script type="text/javascript" language="JavaScript1.2" src="#request.absolutePath#stmenu.js"></script>
<script language="javascript1.2" src="#request.absolutePath#other/scroller.js"></script>
<script language="javascript1.2" src="#request.absolutePath#other/jsfile.js"></script>
<cfajaximport tags="cfform">
</head>
<Body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
  <tr>
  
  <td width="50%" background="#request.absolutePath#images/bg.gif"><img src="#request.absolutePath#images/px1.gif" width="1" height="1" alt="" border="0"></td>
  <td valign="bottom" background="#request.absolutePath#images/bg_left.gif"><img src="#request.absolutePath#images/bg_left.gif" alt="" width="17" height="16" border="0"></td>
  <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><img src="#request.absolutePath#images/main01.jpg" width="620" align="left" height="123"></td>
              <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="300" height="46" background="#request.absolutePath#images/fon01.gif"><a href="index.cfm"><img src="#request.absolutePath#images/but001.gif" width="67" height="46" border="0"></a><img src="#request.absolutePath#images/separator.gif" width="2" height="46"><a href="contact.cfm"><img src="#request.absolutePath#images/but002.gif" alt="Advanced Search" width="90" height="46" border="0"></a><img src="#request.absolutePath#images/separator.gif" width="2" height="46"><a href="advsearch.cfm"><img src="#request.absolutePath#images/but003.gif" alt="Contact Us" width="80" height="46" border="0"></a></td>
                  </tr>
                  <tr>
                    <td height="77" background="#request.absolutePath#images/fon02.gif"><table width="235" border="0" align="center" cellpadding="5" cellspacing="0" background="">
                        <tr>
                          <th width="45"><font color="##FFFFFF"> SEARCH</font></th>
                          <td width="139"><input type="Text" name="Input" class="textfield_effect" style="text-align:right;"></td>
                          <td width="21"><input type="submit" value="" class="searchButton" name="search"></td>
                        </tr>
                      </table></td>
                  </tr>
                </table></td>
            </tr>
          </table></td>
      </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" width="100%" background="">
      <tr>
        <td colspan="3"><img src="#request.absolutePath#images/px1.gif" width="1" height="1" alt="" border="0"></td>
      </tr>
      <tr>
        <td bgcolor="##CECECE" colspan="3"><img src="#request.absolutePath#images/px1.gif" width="1" height="1" alt="" border="0"></td>
      </tr>
      <tr>
        <td width="276" align="center"><div id="colorarrow_id" ></div>
          <script type="text/javascript">
var fo = new FlashObject("#request.absolutePath#other/menu.swf","colorarrow","140","180","6","##000000");
    fo.addParam("menu","true");
    fo.addParam("quality","best");
    fo.addParam("scale","noscale");
    fo.addParam("salign","LT");
    fo.addParam("wmode", "transparent");
    fo.write("colorarrow_id");
</script></td>
        <td valign="bottom"><img src="#request.absolutePath#images/e01.gif" alt="" width="2" height="226" border="0"></td>
        <td><table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absolutePath#images/b01.gif" width="243" height="40" alt="" border="0"></a></td>
              <td rowspan="5"><img src="#request.absolutePath#images/top03.gif" width="259" height="200" alt="" border="0"></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absolutePath#images/b02.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absolutePath#images/b03.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absolutePath#images/b04.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absolutePath#images/b05.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td colspan="2" align="right" class="string"><strong>#DateFormat(now(),'dddd, mmmm, dd yyyy')#</strong></td>
            </tr>
          </table></td>
      </tr>
    </table>
  <div align="center" class="dodo"><img src="#request.absolutePath#images/px1.gif" width="1" height="1" alt="" border="0"></div><br>
  <table width="100%">
    <tr>
      <td><cfinclude template="#request.absolutePath#menu.cfm"></td>
    </tr>
  </table>
  <table border="0" cellpadding="2" align="center" cellspacing="2" width="100%">
    <tr valign="top">
    
    <td width="206" align="left" valign="top"><cfinclude template="#request.absolutePath#quick.cfm"><a href="javascript:void(0);" onClick="WinOpen('tellfriend.cfm','500','500');" title="Tell Your Friends"><img title="Tell Your Friends" src="#request.absolutePath#images/tell-a-friend.gif" alt="Tell Your Friends" border="0"></a><a href="forums.cfm" target="_blank" title="Our Discussion Board"><img title="Our Discussion Board" src="#request.absolutePath#images/discussion.jpg" alt="Discussion Board" width="100" height="70" border="0"></a><br></td>
    <td>
    </cfoutput>
</cfsavecontent>
 
<cfsavecontent variable="bottombar">
</td>
    
    </tr>
    
  </table>
  <br>
  <cfinclude template="#request.absolutePath#footer.cfm">
</body>
</html>
</cfsavecontent>
 
 i am getting error: as:
 
The filename, directory name, or volume label syntax is incorrect

Open in new window

Comment
Watch Question

ZvonkoSystems architect
CERTIFIED EXPERT
Top Expert 2006

Commented:
First problem is that upper page can be called ONLY when it is a response page to a FORM subission.
Only when the FORM strusture is supplied you will get a Country value.
So you first have to check whether that FORM. structure is present.
Like this:
<cfif isDefined("FORM.ALLFIELDS") >
...


Next you must not use the full path to a web page part like this one:
<script language="javascript1.2" src="#request.absolutePath#other/flashobject.js" type="text/javascript"></script>
var fo = new FlashObject("#request.absolutePath#other/menu.swf","colorarrow","140","180","6","##000000");
<div align="center" class="dodo"><img src="#request.absolutePath#images/px1.gif" width="1" height="1" alt="" border="0"></div><br>
 
The correct syntax is this:
<script language="javascript1.2" src="other/flashobject.js" type="text/javascript"></script>
var fo = new FlashObject("other/menu.swf","colorarrow","140","180","6","##000000");
<div align="center" class="dodo"><img src="images/px1.gif" width="1" height="1" alt="" border="0"></div><br>
 



CERTIFIED EXPERT

Author

Commented:
My form Stucture passed correctly, i checked it using cfdump. 
why i am using the  #request.absolutepath#, the reason is the makepages.cfm is in the admin folder and what the contents i have in the makepages.cfm are outside the admin folder, i mean outside the admin folder but in other folders, so i am trying to give the abosolute path to make it work anyhow.
path goes correctas:

c:\inetpub\wwwroot\educationconsulatant\others\menu.swf

first, as Zvonko says, good programming would be to check that the form exists ...
such as:

<cfif IsDefined("form.countryURL")>
    <cfset form_countryURL=form.countryURL>
<cfelseif IsDefined("url.countryURL")>
    <cfset form_countryURL=url.countryURL>
<cfelse>
    <cfset form_countryURL='US'>
</cfif>
This way, if the page is called in any way that is unexpected by you, there is a default value.

Second, you are getting confused with your "absolute" paths ...
    *    the "Absolute" path required by Coldfusion (CFINCLUDE, CFFILE, CFIMAGE, etc), is the absolute file as found on the server harddrive. (eg: c:\inetpub\wwwroot\educationconsulatant\others\menu.swf")
    *    the "Absolute" path required by the Browser (IMG,LINK,SCRIPT,etc)to render the page, is relative to the root folder (eg: \educationconsulatant\others\menu.swf)
    *    the ONLY time when the Absolute path "c:\inetpub\wwwroot\..." will work in a browser, is on the machine on which the webserver, and coldfusion reside ...

In you example, does #request.absolutpath# end in "\" ?
<cfset request.absolutepath='c:\inetpub\wwwroot\educationconsultant\'>
<cfset request.absoluteDIR='c:\inetpub\wwwroot\educationconsultant\'>
<cfset request.absoluteURL='/educationconsultant/'>
 
<cfsavecontent variable="topbar">
<cfoutput>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<cfinclude template="#request.absoluteDIR#meta.cfm">
<link rel="stylesheet" type="text/css" href="#request.absoluteURL#style.cfm" media="screen" />
<script language="javascript" type="text/javascript" src="#request.absoluteURL#other/flashobject.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="#request.absoluteURL#stmenu.js"></script>
<script language="javascript" type="text/javascript" src="#request.absoluteURL#other/scroller.js"></script>
<script language="javascript" type="text/javascript" src="#request.absoluteURL#other/jsfile.js"></script>
<cfajaximport tags="cfform">
</head>
<Body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
  <tr>
  
  <td width="50%" background="#request.absoluteURL#images/bg.gif"><img src="#request.absoluteURL#images/px1.gif" width="1" height="1" alt="" border="0"></td>
  <td valign="bottom" background="#request.absoluteURL#images/bg_left.gif"><img src="#request.absoluteURL#images/bg_left.gif" alt="" width="17" height="16" border="0"></td>
  <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><img src="#request.absoluteURL#images/main01.jpg" width="620" align="left" height="123"></td>
              <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="300" height="46" background="#request.absoluteURL#images/fon01.gif"><a href="index.cfm"><img src="#request.absoluteURL#images/but001.gif" width="67" height="46" border="0"></a><img src="#request.absoluteURL#images/separator.gif" width="2" height="46"><a href="contact.cfm"><img src="#request.absoluteURL#images/but002.gif" alt="Advanced Search" width="90" height="46" border="0"></a><img src="#request.absoluteURL#images/separator.gif" width="2" height="46"><a href="advsearch.cfm"><img src="#request.absoluteURL#images/but003.gif" alt="Contact Us" width="80" height="46" border="0"></a></td>
                  </tr>
                  <tr>
                    <td height="77" background="#request.absoluteURL#images/fon02.gif"><table width="235" border="0" align="center" cellpadding="5" cellspacing="0" background="">
                        <tr>
                          <th width="45"><font color="##FFFFFF"> SEARCH</font></th>
                          <td width="139"><input type="Text" name="Input" class="textfield_effect" style="text-align:right;"></td>
                          <td width="21"><input type="submit" value="" class="searchButton" name="search"></td>
                        </tr>
                      </table></td>
                  </tr>
                </table></td>
            </tr>
          </table></td>
      </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" width="100%" background="">
      <tr>
        <td colspan="3"><img src="#request.absoluteURL#images/px1.gif" width="1" height="1" alt="" border="0"></td>
      </tr>
      <tr>
        <td bgcolor="##CECECE" colspan="3"><img src="#request.absoluteURL#images/px1.gif" width="1" height="1" alt="" border="0"></td>
      </tr>
      <tr>
        <td width="276" align="center"><div id="colorarrow_id" ></div>
          <script type="text/javascript">
var fo = new FlashObject("#request.absoluteURL#other/menu.swf","colorarrow","140","180","6","##000000");
    fo.addParam("menu","true");
    fo.addParam("quality","best");
    fo.addParam("scale","noscale");
    fo.addParam("salign","LT");
    fo.addParam("wmode", "transparent");
    fo.write("colorarrow_id");
</script></td>
        <td valign="bottom"><img src="#request.absoluteURL#images/e01.gif" alt="" width="2" height="226" border="0"></td>
        <td><table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absoluteURL#images/b01.gif" width="243" height="40" alt="" border="0"></a></td>
              <td rowspan="5"><img src="#request.absoluteURL#images/top03.gif" width="259" height="200" alt="" border="0"></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absoluteURL#images/b02.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absoluteURL#images/b03.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absoluteURL#images/b04.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td><a href=""><img src="#request.absoluteURL#images/b05.gif" width="243" height="40" alt="" border="0"></a></td>
            </tr>
            <tr>
              <td colspan="2" align="right" class="string"><strong>#DateFormat(now(),'dddd, mmmm, dd yyyy')#</strong></td>
            </tr>
          </table></td>
      </tr>
    </table>
  <div align="center" class="dodo"><img src="#request.absoluteURL#images/px1.gif" width="1" height="1" alt="" border="0"></div><br>
  <table width="100%">
    <tr>
      <td><cfinclude template="#request.absoluteDIR#menu.cfm"></td>
    </tr>
  </table>
  <table border="0" cellpadding="2" align="center" cellspacing="2" width="100%">
    <tr valign="top">
    
    <td width="206" align="left" valign="top"><cfinclude template="#request.absoluteDIR#quick.cfm"><a href="javascript:void(0);" onClick="WinOpen('tellfriend.cfm','500','500');" title="Tell Your Friends"><img title="Tell Your Friends" src="#request.absoluteURL#images/tell-a-friend.gif" alt="Tell Your Friends" border="0"></a><a href="forums.cfm" target="_blank" title="Our Discussion Board"><img title="Our Discussion Board" src="#request.absoluteURL#images/discussion.jpg" alt="Discussion Board" width="100" height="70" border="0"></a><br></td>
    <td>
    </cfoutput>
</cfsavecontent>
 
<cfsavecontent variable="bottombar">
</td>
    
    </tr>
    
  </table>
  <br>
  <cfinclude template="#request.absoluteDIR#footer.cfm">
</body>
</html>
</cfsavecontent>

Open in new window

CERTIFIED EXPERT

Author

Commented:
but still get the same error:
The filename, directory name, or volume label syntax is incorrect
i think i have something going wrong here
<cfinvoke component="#request.cfcPath#.tools" method="addnewdeal" argumentcollection="#form#"/>
      <cfset templatePage = 'makepages.cfm'>
      <cfinclude template="#templatePage#">
      <cffile action="write" file="#request.absolutePath##form.countryURL#.cfm" output="#topbar#">
      <cfset show = "Cool! Successfully Processed">


had put the default form as:
<cfparam name="form.countryurl" default="US"> on top to make sure null value does not go empty
OK ... can you provide the values for:

request.cfcPath
request.absolutPath
form.countryURL.cfm

Also, if it's not too big, can you provide the code for addnewdeal ?

thx
CERTIFIED EXPERT

Author

Commented:
yeah ok no issues, i will provide u full detail here:
<cfset request.basePath = "http://localhost/educationconsultant/">
  <cfset request.absolutePath = "c:\inetpub\wwwroot\educationconsultant\">
<cfset request.cfcpath = cfc>

addnewdeal code:
<cfquery datasource="#request.dsn#" username="#request.user#" password="#request.pass#" name="myset">
    INSERT INTO dealingcountries(country,flagimage,status,countryurl) 
    VALUES (<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.countrieslist)#">,
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.inpoint)#">,
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.enable)#">,
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.countryURL)#">)
    </cfquery>


what i did is this:
<cfset form.countryURL = #form.countrieslist#>
      <cfinvoke component="#request.cfcPath#.tools" method="addnewdeal" argumentcollection="#form#"/>
      <!---<cfset templatePage = 'makepages.cfm'>
      <cfinclude template="#templatePage#">--->
      <cffile action="write" file="#request.absolutePath##form.countryURL#.cfm" output="Any">
      <cfset show = "Cool! Successfully Processed">


just diabled the
      <!---<cfset templatePage = 'makepages.cfm'>
      <cfinclude template="#templatePage#">--->


and it worked but it created the page and the content of the created page was: ANY because i have written something like this:
     <cffile action="write" file="#request.absolutePath##form.countryURL#.cfm" output="Any">
So what is actually going wrong here, i do not know
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Author

Commented:
Ok i played it with and get around something, i did made some changes like:
<cfset newway = #Replace(request.absoluteURL,'/','','All')#>
<cfdump var="#newway#">
<cfif IsDefined("#newway#")>
 <cfset request.cfcPath = "admin.cfc">
</cfif>
<cfinclude template="#request.absoluteURL#meta.cfm">


using request.absoluteURL in my included files.
  • First i removed all included files from the makepages.cfm template
  • then it worked.
  • then i changed the path of the included files as above
  • they did not worked.
  • i got error:Ensure that the name is correct and that the component or interface exists. Could not find the ColdFusion Component or Interface cfc.tools.
  • This was coming as it was getting the path from application.cfc file as request.cfcpath = cfc.tools
  • while i hardcoded it to admin.cfc.tools. it worked.
  • then i added the above code u see
  • <cfset newway = #Replace(request.absoluteURL,'/','','All')#>
    <cfdump var="#newway#">
    <cfif IsDefined("#newway#")>
     <cfset request.cfcPath = "admin.cfc">
    </cfif>
  • to get the required cfc for this page but it did not worked.
  • Something going wrong here
One more stuff, what i need to incclude a<cfoutput>#now()#</cfoutput> to be dynamic.

CERTIFIED EXPERT

Author

Commented:
Thanks, Solved

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.