ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Creating a list from a textarea publish input

August 07, 2007 2:56pm

Subscribe [5]
  • #1 / Aug 07, 2007 2:56pm

    gregwood

    19 posts

    Hi there everyone,

    The title says it all really. One of my custom fields relates to the pros of a product (another for cons) and currently I’ve got a textarea set to format
    so that the inputs display as I need. Users would enter one pro or con per line.

    However for semantic purposes, I’d like each line of the list (in the textarea) to correspond with a <li> in the code, all within an <ul>. Any suggestions of how to do this without using a separate custom field for each list item?

    Thanks

  • #2 / Aug 07, 2007 3:15pm

    Ingmar

    29245 posts

    Some PHP, probably. Use explode() on ‘
    ’ (or whatever), than loop through the resulting array and output any which way you like.

  • #3 / Aug 07, 2007 4:34pm

    Greg Salt

    3988 posts

    Or you could enable Textile formatting (or use it on the template) for that textarea. Then your users would only have to type:

    * a pro
    * another pro
    * maybe a con
    * and perhaps another con

    That would be output as:

    <ul>
    <li>a pro</li>
    <li>another pro</li>
    <li>maybe a con</li>
    <li>and perhaps another con</li>
    </ul>

    Cheers

    Dry

  • #4 / Aug 09, 2007 9:58am

    Wolfram

    115 posts

    If it will only be list items in those pro and con fields, maybe you could also define an <li> HTML button in EE and ask your users to double klick every line and apply the button. If you set field formatting to none and wrap the field like this

    <ul>
    {pros}
    </ul>

    you´ll also end up with correct markup. Wolfram

  • #5 / Aug 11, 2007 6:17am

    gregwood

    19 posts

    Cheers guys, loadsa good feedback. I’m not actually up to this point in development yet, just thinking ahead, but so far I’m leaning towards something like this:

    <?php
    $items  =  explode( ", ", "list item 1, list item 2, list item 3" );
    echo  "<ul>";
    foreach(  $items  as  $item  )
    {
           echo  "<li>$item</li>";
    }
    echo  "</ul>";
    ?>

    Any thoughts?

  • #6 / Jan 02, 2008 11:05pm

    Dane Thomas

    139 posts

    Greg,

    Just wondering if you worked out a solution for this?

    I have the exact same issue, I have a text area that I’m requiring users to enter a product list - a product on each line within the text area. I too want to output this as a <li> </li> in the template for formatting (or even have the output split over two columns which I’m not sure how that will work.

    I’m fairly versed with EE but not as experience with straight PHP - just wondering if the above code was what you used or if you could explain in a little more detail what I need to do to get this working in my template?

    Thanks.

  • #7 / Jan 02, 2008 11:44pm

    Lisa Wess

    20502 posts

    You might look for the ListMaker plugin, as that’ll make each new line in the textarea be its own list item.  I’ve used that for a few things - it’s very useful.

  • #8 / Jan 03, 2008 12:01am

    Dane Thomas

    139 posts

    Thanks for that Lisa - I’ll check that out. Another plugin I wasn’t aware of.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases