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.

Split entry with More tag or php split()

July 23, 2012 5:48pm

Subscribe [2]
  • #1 / Jul 23, 2012 5:48pm

    nurotic

    8 posts

    Hi all,

    I have just started using EE2, and currently using it to rebuild our company website.

    I have a channel with a field called {page_content} and I want to be able to split that field, with a more tag if you will.

    In php i would simply do:

    <?php
    
    $splitContent = split('<!--MORE-->', $content);
    
    echo $splitContent[0];
    
    // Break for whatever reason
    
    echo $splitContent[1];
    
    ?>

    I can see how to split multiple entries across pages, but can’t see a way to split fields. I tried to use php in the template

    {exp:channel:entries channel='static_pages'}
     <div class="row">
      <div class="span4">
       <?php $splitcontent = explode("<hr>", {page_content}; ?>
       <?php echo $splitcontent[0]; ?>
      </div>
      <div class="span3">
       <?php echo $splitcontent[1]; ?>
      </div>  
     </div>
    {/exp:channel:entries}

    but no joy.

    Any guidance will be appreciated.

     

  • #2 / Jul 24, 2012 1:53pm

    Dan Decker

    7338 posts

    Hi nurotic,

    Thanks for posting to the forums and welcome to ExpressionEngine!

    What you want to do is entirely possible, but not out-of-the-box. There are several character limiters and word limiters, but Hacksaw has a great feature set and should be very close to what you are after.

    Let me know if you have any other questions!

    Cheers,

  • #3 / Jul 25, 2012 5:03am

    nurotic

    8 posts

    Thanks for that link will take a look.

    I did manage to get it to work and discovered that the reason I was having much difficulty was due to a anchor tag in the content. The quote marks broke the php. Is there a way to escape content?

  • #4 / Jul 26, 2012 10:33am

    Robin Sowell

    13255 posts

    Ah- yes, that will do it working in a template.  The best approach would be to use an existing plugin or write your own.  It would be a fairly simple project- or as Dan points out, there are some existing that should do what you want.

    The problem doing it in a template- if you’re parsing on output (which you have to be for this) then the variable is really whatever the contents are.  And unless you know for sure there are no single quotes (or conversely no double quotes) you run into the problem you currently face.  With a plugin, you can get back a variable to play with rather than a string- so you avoid the issue.

    That’s really the way to go on this one.  Make sense?

  • #5 / Jul 26, 2012 6:26pm

    nurotic

    8 posts

    Aha! I see. That should be easy as I have been previously using code igniter. I’ll give it a go.

    Thanks.

  • #6 / Jul 26, 2012 8:00pm

    Robin Sowell

    13255 posts

    😉  Yep- it should be way simple for you.  Grab the pi.xml_encode.php plugin from system/ee/plugins for a super simple example and then check the docs on plugin tag pairs and you should be able to put together a plugin that does what you want in about 15 minutes.

    I think you’ll enjoy playing with EE 😉

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

ExpressionEngine News!

#eecms, #events, #releases