getExcerpt() public method

Get the excerpt of a given piece of text.
public getExcerpt ( integer $length = 200, boolean $includeTitle = false, array | string | null $focus = null ) : string | null
$length integer
$includeTitle boolean
$focus array | string | null
return string | null
示例#1
0
 /**
  * Create an excerpt for the content.
  *
  * @param integer      $length
  * @param boolean      $includeTitle
  * @param string|array $focus
  *
  * @return \Twig_Markup
  */
 public function getExcerpt($length = 200, $includeTitle = false, $focus = null)
 {
     $excerptParts = [];
     if (!empty($this->contenttype['fields'])) {
         foreach ($this->contenttype['fields'] as $key => $field) {
             // Skip empty fields, and fields used as 'title'.
             if (!isset($this->values[$key]) || in_array($key, $this->getTitleColumnName())) {
                 continue;
             }
             // add 'text', 'html' and 'textarea' fields.
             if (in_array($field['type'], ['text', 'html', 'textarea'])) {
                 $excerptParts[] = $this->values[$key];
             }
             // add 'markdown' field
             if ($field['type'] === 'markdown') {
                 $excerptParts[] = $this->app['markdown']->text($this->values[$key]);
             }
         }
     }
     $excerpter = new Excerpt(implode(' ', $excerptParts), $this->getTitle());
     $excerpt = $excerpter->getExcerpt($length, $includeTitle, $focus);
     return new \Twig_Markup($excerpt, 'UTF-8');
 }
示例#2
0
 /**
  * Create an excerpt for the given content.
  *
  * @param \Bolt\Legacy\Content|array|string $content
  * @param integer                           $length  Defaults to 200 characters
  * @param array|string|null                 $focus
  *
  * @return string Resulting excerpt
  */
 public function excerpt($content, $length = 200, $focus = null)
 {
     $excerpter = new Excerpt($content);
     $excerpt = $excerpter->getExcerpt($length, false, $focus);
     return $excerpt;
 }