Solved

Coldfusion - New Line without using <br>

Posted on 2013-06-06
5
926 Views
Last Modified: 2013-06-06
Hello experts
I have a function to create a part of my htaccess file.
I'm using the following code:
<cffunction name="fwriteurlcategories" access="private" returntype="void">
  <!--- Get information from categories table--->
  <cfset var getcategories = fcategories()>
  <cfoutput query="geturlrwcategories">
   <cfset newline = "ReWriteRule ^#newlinkalias#$ index.cfm?action=viewcategory&category=#categoryid#">
   <cffile action = "append" file="#variables.catalogpath#.htaccess" output="#newline#" addnewline="yes" charset="utf-8">
  </cfoutput>
</cffunction>

Open in new window


This way i'm adding each row in a new line in the htaccess file.
Is there any way to 1) create the content with all the rewriterules2) and append it to the document?
I tried to use the query inside a cfsavecontent but i can't get the rewriterules in new lines.

Any help?
0
Comment
Question by:Panos
  • 3
  • 2
5 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39226984
If I'm understanding correctly, the problem is new lines are o/s dependent.  

* On windows it's: chr(13) & chr(10)  and Unix its:  chr(10)
* If you have createObject access, you can use System.getProperty("line.separator") instead.

So you can use cfsavecontent .. but it preserves all white space, so you may need to put it all on the same line. Something like this:

Edit - Add final write to disk
...
<cfset var content = "">
<cfset var newLine = chr(13)&chr(10)>
<cfsavecontent variable="content">
 <cfoutput query="geturlrwcategories">ReWriteRule ^#newlinkalias#$ index.cfm?action=viewcategory&category=#categoryid##newLine#</cfoutput>
</cfsavecontent>
<!--- overwrite existing file --->
<cffile action="write" file="#variables.catalogpath#.htaccess" output="#newline#" charset="utf-8">

Open in new window

0
 
LVL 2

Author Comment

by:Panos
ID: 39227276
Thank you agx.
It is working
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 39227278
regards
panos
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39227459
Correction for the archives.  That very last line:

     <cffile action="write" file="#variables.catalogpath#.htaccess"
            output="#newline#" charset="utf-8">

should be this instead:

     <cffile action="write" file="#variables.catalogpath#.htaccess"
            output="#content#" charset="utf-8">
0
 
LVL 2

Author Comment

by:Panos
ID: 39227573
Thank you agx.
I have allready correct this.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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