expressionengine - Importing PHP string with quotes -
so i'm importing expressionengine fields php array. want display 1 field, called {gearboxx_body}, unless field has more 300 characters, in case want display field called {article_blurb}. i'm pretty sure there isn't way in expressionengine fields , conditionals, tried php, i'm starting learn:
<?php $info = array('{gearboxx_body}','{article_blurb}'); if(mb_strlen($info[0]) <= 300) echo($info[0]); } else { echo($info[1]); } ?>
so works well, there's problem. if tag includes apostrophes or quote marks, ends string , page won't load. can this? i've tried replace quote marks in string, have have loaded string fields first, , page broken.
hopefully made sense. suggestions?
i recommend handle in ee plugin rather in template:
- faster render (because don't need overhead of php in templates)
- more secure , reliable
- faster develop once basics of ee development down which useful life skill
- all around best-practice
the plugin have in mind takes 3 parameters:
body, blurb , character limit.
let's call plugin "blurby". in template have this:
{exp:blurby body="{gearboxx_body}" blurb="{article_blurb}" char_limit="300"}
it variably returns either of fields based on logic define in plugin itself.
see plugin developer documentation.
alternatively use dreaded heredoc syntax set variables before passing them array:
$body = <<<eot {gearboxx_body} eot; $blurb = <<<eot {article_blurb} eot;
Comments
Post a Comment