We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27330
    • 884 Posts
    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.
      • 3749
      • 24,544 Posts
      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;




        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 27330
        • 884 Posts
        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?
          • 3749
          • 24,544 Posts
          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.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 27330
            • 884 Posts
            nice. the $crlf=’#’ works fine. still better than open/closing tags.
            thanks a lot man. what a beauty in 9 lines.
              • 36416
              • 589 Posts
              Here’s relevant PHx modifier that I wrote:
              [tt]lineslist.phx.php[/tt]
              <?php
              $arlst = explode("\n", $output);
              $output = "";
              foreach ($arlst as $li) {
                $output .= "<li>".trim($li)."</li>\n";
              }
              return $output;
              


              Usage inside templating chunks:
              [+someTVname:lineslist+]

                • 3749
                • 24,544 Posts
                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. wink
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 27330
                  • 884 Posts
                  Eol i wonder what type of tv you used. when i use just textarea with no widget the snippet don’t pick up the EOL smiley
                    • 36416
                    • 589 Posts
                    Quote from: sinbad at Jan 04, 2010, 09:28 PM

                    Eol i wonder what type of tv you used. when i use just textarea with no widget the snippet don’t pick up the EOL smiley

                    Textarea without output widget works fine here (UTF-8 site, managed with Firefox 3.5.6 on WinXP).