Solved

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

Posted on 2006-07-05
10
332 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
Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
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 125 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

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Website Test Question 6 131
connection string question 2 73
PHP in Apache server 20 105
UPLOAD FILE TO Web API USING POST 5 132
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
What You Need to Know when Searching for a Webhost Provider
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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