0

This should be straightforward. I just need to take my event summary from the Solspace Calendar plugin and truncate it to say 280 characters. I have PHP set to "Yes", and "Output" parsing stage. It is breaking and not rendering the template. I'm assuming it's because I'm using it in a variable pair. Below is the template:

{exp:calendar:cal calendar_id="214" date_range_start="-2 weeks" date_range_end="+5 weeks"}
{events}

    <div class="eventPopup" data-date="{event_start_date format="%Y-%m-%d"}">
        <div class="eventPopupHeader">
            {event_start_date format="%F %j, %Y"}
        </div>
        <div class="closeButton"><a href="javascript:void(0)"><img src="{siteroot}images/uploads/main/closeButton.png" width="30" height="30" alt="close button"></a></div>
        <div style="clear:both"></div>
        <div class="subnavContent">
            {if event_pic != ""}<img src="{event_pic}" width="246" height="166" alt="menu pic"><div style="clear:both"></div>{/if}
            <h3><a href="/haa/event/{entry_id}">{event_title}</a></h3><p>{event_location} - <?php echo substr("{event_summary}", 0, 280); ?></p>
        </div>
    </div>
{/events}
{/exp:calendar:cal}
1
  • Does the template render at all? ie do you get a partial output with junk in the event p tag, or a WSOD, 404 or something else? Can you supply examples of the {event_summary} so we can identify any formatting issues? does it all work with out the php substr?? Lastly, is events a matrix/grid??
    – Blatant
    May 15, 2015 at 10:28

2 Answers 2

4

Why aren't you just using https://devot-ee.com/add-ons/character-limiter ??

Also, if PHP is set on output, what happens when

{event_summary}

has a value like this?

And the event was great, he said "Everything is healing nicely!"
4
  • As JChrono says, you need to watch out for double quote's in your string, you can perhaps use addslashes to fix this sort of thing , also if your event_summary contains HTML (Perhaps its a WYSIWYG feild??) you could try out TruncHtml which Ive used before, does a good job.
    – Blatant
    May 15, 2015 at 10:25
  • Morning Blatant! Did I screw up in my answer (ie does the EE parser watch for escaping quotes when it evals PHP)? I didn't have time to test or jump in the core.
    – jrothafer
    May 15, 2015 at 11:44
  • 1
    My neither!!! I was thinking about quotes in tags as I read this and intend to dial up an example, otherwise I might write a quick gettext -> addslashes extension to help with thsis sort of thang...
    – Blatant
    May 15, 2015 at 13:15
  • 1
    I was wondering if there was something like that. EE doesn't seem to like PHP very well. Thanks for the link.
    – The Hawk
    May 15, 2015 at 15:04
0

There are many plugins for this already.

Here are a few:

http://www.causingeffect.com/software/expressionengine/ce-string

https://devot-ee.com/search/results?keywords=string+length&addon_version_support=ee2

Or you could roll your own...

1
  • Why would you roll oyur own or push for a paid for 3rd party module when EllisLabs offer a 1st party free module??
    – Blatant
    May 15, 2015 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.