Solved

Coldfusion - New Line without using <br>

Posted on 2013-06-06
5
985 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 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