hi boys/gals,
I have a client site where he list features for products.
the li is made by [*TV_features*] which is a plain text area field with default of "<li>1st feature</li><li>2nd feature</li>" etc.
is there any snippet out there that will allow him just to insert the features in the TV, one per line, and the <li> will be generated on the fly from his new rows?
not that important but would be nice to explain him to type only the features one per line instead of explaining him to read between the lines.
thanks for any input.
Quote from: sinbad at Jan 03, 2010, 12:27 PM
the li is made by [*TV_features*] which is a plain text area field with default of "<li>1st feature</li><li>2nd feature</li>" etc.
is there any snippet out there that will allow him just to insert the features in the TV, one per line, and the <li> will be generated on the fly from his new rows?
A quick snippet called Lister should be able to parse the TV for you:
[!Lister? &tvText=`[*TV_features*]`!]
Something like this:
<?php
$crlf = "\n"; // (not sure what the line ending character would be in the TV in your DB)
$lines = array();
$lines = explode($crlf, $tvText);
$output = '<ul>';
foreach($lines as $line) {
$output.= '<li>' . $line . '</li>';
}
$output .= '</ul>';
return $output;
thanks Bob,
it’s outputting <ul>
<li>some feature 2nd feature 3rd feature</li>
</ul> without recognizing the new line.
what other end of line character can it be if not /n?
I’m not sure. The \n should actually be in double quotes (my bad). That might do it. You could also try "\r".
I guess it’s possible that there are no EOL characters in the saved TV. One way to be sure would be to dump the DB table containing the TV and look at the resulting file with a hex editor.
Worst case -- you could always use something like $crlf=’#’ and put a # at the end of each line.
nice. the $crlf=’#’ works fine. still better than open/closing tags.
thanks a lot man. what a beauty in 9 lines.
If Eol’s code works, then my original code with the \n in double quotes should work: "\n"
Given the handle, Eol should be an expert in this area.