Exemple #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');
 }
Exemple #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;
 }