Solved

Coldfusion - New Line without using <br>

Posted on 2013-06-06
5
840 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now