?
Solved

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

Posted on 2006-07-05
10
Medium Priority
?
336 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

807 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