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.

Stripping the first <p> in a long entry.

July 12, 2007 12:07pm

Subscribe [0]
  • #1 / Jul 12, 2007 12:07pm

    bjsteiger

    87 posts

    We have multiple entries that are full of multiple paragraphs, however due to some layout conventions we want to strip only the opening paragraph tag because we are combining two different custom fields - like this:

    {n_location} — {n_body}

    Basically we want the returned results from {n_body} to be:

    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum fringilla felis et ligula. Aliquam tempor porttitor ligula.
    
    In ultrices molestie nulla. Duis ut ante quis dolor accumsan aliquam. Etiam egestas, eros et vulputate ultrices, ligula tortor laoreet nisi, ut rutrum neque tortor sit amet lacus. Maecenas eu nisl. Donec eu velit. Integer diam mauris, aliquet ac, nonummy at, interdum sit amet, purus.
    
    Ut vel arcu. Mauris ornare. Cras dui magna, tristique sed, gravida nec, pretium sit amet, neque. Sed pretium. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Etiam fringilla hendrerit lacus.
  • #2 / Jul 12, 2007 12:33pm

    Daniel Walton

    553 posts

    Are your entries only ever going to be P’s? no other tags?

  • #3 / Jul 12, 2007 12:36pm

    bjsteiger

    87 posts

    I’m not sure if I understand what you asking.

    There will be other html tags in there <strong>, <em>, <ul>, <li>, <ol>, <blockquote>, <img> <a>—however, it will always only start with a .

    Does that make better sense?

    bjs

  • #4 / Jul 12, 2007 12:46pm

    e-man

    1816 posts

    I’m assuming here that {n_body} always has an opening tag.

    <?php
    $output="{n_body}"
    echo substr($output, 3);
    ?>

    Allow for php in your template of course 😊

  • #5 / Jul 12, 2007 12:49pm

    bjsteiger

    87 posts

    How would I drop this into a plugin so I don’t have to turn on PHP on every page in our site?

    bjs

  • #6 / Jul 12, 2007 12:54pm

    e-man

    1816 posts

    How would I drop this into a plugin so I don’t have to turn on PHP on every page in our site?

    bjs

    You could put above code in an embed and set your php settings on the embed template.

  • #7 / Jul 12, 2007 1:04pm

    bjsteiger

    87 posts

    very cool

  • #8 / Jul 12, 2007 1:09pm

    bjsteiger

    87 posts

    I tried this and it didn’t seem to work - I tried it both as output and input, and I also tried as an embed and also on the same page.

  • #9 / Jul 12, 2007 1:12pm

    e-man

    1816 posts

    Can you post the full code of your embed and your template?

  • #10 / Jul 12, 2007 2:03pm

    e-man

    1816 posts

    I tested this and it works.
    Code for your embed template (set php to input)

    <?php 
    $your_variable = <<<ABCD
    {n_body}
    ABCD;
    
    echo (substr($your_variable, 3));
    ?>

    in your main template (set php to output) use

    {embed="name of template group/name of embed template"}

    and make sure this is between the {exp:weblog} tags. Worked for me so see what happens.

  • #11 / Jul 13, 2007 11:49am

    bjsteiger

    87 posts

    The problem I ran into was that I didn’t set my master teplate to PHP. I was trying to not have to set every template to have PHP on. I will give this a shot

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

ExpressionEngine News!

#eecms, #events, #releases