Skip to content

Commit

Permalink
#20 - Correct summary shortcode and add 'max' pref
Browse files Browse the repository at this point in the history
  • Loading branch information
Moc committed Aug 22, 2022
1 parent 41c27ce commit 777872f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions cookbook_shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,25 @@ function sc_cookbook_tagcloud($parm = array())
');
}

/**
* Renders the summary of a recipe
*
* @param int $max - Limits the summary to a maximum amount of characters
*
* @example {COOKBOOK_SUMMARY: max=150} // returns the summary limited to 150 characters.
*
*/
function sc_cookbook_summary($parm = array())
{
if($parm['max'])
{
$summary = e107::getParser()->toText($this->var["r_summary"]);
$summary = str_replace("\n", ' ', $summary);
$summary = e107::getParser()->truncate($summary, $parm['max']);

return $summary;
}

return e107::getParser()->toHTML($this->var["r_summary"], TRUE);
}

Expand Down
2 changes: 1 addition & 1 deletion templates/cookbook_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{COOKBOOK_RECIPE_THUMB}
<div class="caption text-center">
<h3>{COOKBOOK_RECIPE_NAME}</h3>
<p>{COOKBOOK_RECIPE_SUMMARY}</p>
<p>{COOKBOOK_SUMMARY: max=150}</p>
<ul class="list-inline text-center">
<li>{GLYPH=fa-clock} {COOKBOOK_TIME}</li>
Expand Down

0 comments on commit 777872f

Please sign in to comment.