?
Solved

Count Paragraphs in <cfoutput> of text area data? // Insert image after 1st paragraph?

Posted on 2006-07-05
10
Medium Priority
?
334 Views
Last Modified: 2013-12-24
Is there any way to count paragraphs within the <cfoutput> of a textarea field?
I want to create a page that inserts a div containing another field's data ( photo in this case ) after the first paragraph of an article... .somewhat like this ( pls ignore broken code on sides of page )
http://kanabguide.com/html/offroadtours.shtml

That is the old page, static html.
I want my dynamic output to look like this - one paragraph, then the photo div with dynamic file, caption, alt tag, etc..  then
the rest of the article.


Can it be done?

??

Maybe I have to place the text twice,
trimming everything after the first paragraph the first time,
and trimming off the first paragraph the second time?

My plan is to use this in conjunction with #paragraphFormat#
so maybe I can replace the second <p> in the output with some other code?
0
Comment
Question by:MichaelEvangelista
[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
  • 5
  • 5
10 Comments
 
LVL 13

Expert Comment

by:usachrisk1983
ID: 17046184
Where is the data coming from, and what constitutes a paragraph (a line break, two line breaks, etc)?
0
 

Author Comment

by:MichaelEvangelista
ID: 17046240
Hi Chris -

The data is coming from a mySQL database ( text field type ), and the text is being input via a <cftextarea on a simple web 'admin' form.

A double carriage return creates the new paragraph in the form input.
The output, using #paragraphformat(text)#, creates <p> before and </p> after each paragraph

Here is a temporary output page... you can see what I have so far
http://kanabguide.com.wehostwebsites.com/articleDetails.cfm?recordID=54
0
 
LVL 13

Expert Comment

by:usachrisk1983
ID: 17046265
How about doing something like:

<cfset variables.mypara = paragraphformat(text)>
<cfset variables.mypara = ReplaceNoCase('</p>','</p><img src="someimage.jpg">')>

That will add the image tag after the first paragraph ends.  You can put it inside the <P> by moving the <IMG> tag, and could obviously replace the hard coded src file with a line from the database.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 13

Expert Comment

by:usachrisk1983
ID: 17046273
Sorry, correction to the code:

<cfset variables.mypara = paragraphformat(text)>
<cfset variables.mypara = ReplaceNoCase(variables.mypara,'</p>','</p><img src="someimage.jpg">')>

Also, this assumes you have already gotten the text from the database, which it looks like you can do just fine.
0
 

Author Comment

by:MichaelEvangelista
ID: 17046446
hmmm.... seems like it ought to work, but no joy just yet

I have
<cfset variables.mypara = paragraphformat(recordMainText)>
<cfset variables.mypara = ReplaceNoCase(variables.mypara,'</p>','</p><img src="MREcfCMS/images/full/#recordPhotoFilename#">')>
<p>#variables.mypara#</p>

I am getting the text, but not the image.
http://kanabguide.com.wehostwebsites.com/articleDetails.cfm?recordID=54

Another thing here, I need to insert a div with a few elements, not just the image..
At first, I tried this with the full div code, same results

<cfset variables.mypara = ReplaceNoCase(variables.mypara,'</p>','</p><div class="photowrap"><div align="center"><img src="MREcfCMS/images/full/#recordPhotoFilename#"></div><p class="centered">#recordPhotoTitle#</p><p class="caption">#recordPhotoCaption#</p></div>')>

Seems like it should work, am I missing something?
0
 

Author Comment

by:MichaelEvangelista
ID: 17046681
Someone else suggested listfirst and listrest with the paragraph tag as separator.
Trying that now.
0
 

Author Comment

by:MichaelEvangelista
ID: 17046929
That listfirst code worked!!
(Thanks to ian on the coldfusion forum)

The only thing is that listfirst and listrest both use a single character as a delimiter,
essentially replacing it with a break in the list.
I couldnt use any letters, and <p> wont work becase it is more than on character.

So, I tweaked it a bit to insert a pipe | after the first paragraph
which I know will not be in the text, then use that | character to break the list.

Seems to be working great!

HERE IS A SAMPLE PAGE
http://kanabguide.com.wehostwebsites.com/articleDetails.cfm?recordID=54


HERE IS THE CODE I AM USING
<!--- set up the text output by adding a | after the first paragraph --->
<cfset recordTextFormatted = Replace(#paragraphformat(recordMainText)#, "#chr(13)##chr(10)#", "<p>|")>

<p>#listFirst(recordTextFormatted,"|")#</p>
<div class="photowrap">
 <div align="center"><img src="MREcfCMS/images/full/#recordPhotoFilename#">
 </div>
 <p class="centered">#recordPhotoTitle#</p>
<p class="caption">#recordPhotoCaption#</p>
</div>
<p>#listRest(recordTextFormatted,"|")#</p>
0
 
LVL 13

Accepted Solution

by:
usachrisk1983 earned 375 total points
ID: 17050136
Glad you got it working :)

For what it's worth, chances are that if you looked at the HTML in the original code, it would have inserted the variable as text instead of a variable.  The fix to this would have been:

<cfset variables.mypara = ReplaceNoCase(variables.mypara,'</p>','</p><img src="MREcfCMS/images/full/' & recordPhotoFilename & '">')>
0
 

Author Comment

by:MichaelEvangelista
ID: 17050406
AH thanks. I will mark this page and try again at some point.
Speaking of points... I will accept your answer.
thanks
0
 
LVL 13

Expert Comment

by:usachrisk1983
ID: 17050855
Thanks, good luck :)
0

Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
What You Need to Know when Searching for a Webhost Provider
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
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.
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

770 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