Excerpt breaks `&`?

Hi,

I use a model to customize the “title” of a page. Using a “excerpt” turns a & into a &.
Is this an expected behavior?

model.php

public function title(): Kirby\Content\Field
{
    return $this->headline()->excerpt(50)->or('podcast');
}

headline:

Hirn & Heinrich - der Wissenspodcast des Deutschen Zentrums für Neurodegenerative Erkrankungen e.V. (DZNE)

Result:

Hirn & Heinrich - der Wissenspodcast des …
     ^^^^^

How to keep the & as it is?

Thanks and have a nice day.

ciao, Stefan

I have a similar problem with automatically generated titles in the page creation dialog und just posted an issue on Github:

Hope this can get fixed soon…

Are you using a Writer field for headline?

Hi Tobias,

not sure … you mean Writer | Kirby CMS ?
Not in my case, it’s a default “text” field

headline:
  type: text
  label: Titel / Überschrift

The problem is that the content that should be displayed as the “title” is escaped. See the github ticket linked above.

Yes, because the Writer field internally escapes when saving to the content file which leads to double escaping

Yeah, i see

My case is different, because I am not using “title” nor “slug” (which are escaped by default), but a default text field and an own page model for displaying the “title”

public function title(): Kirby\Content\Field
{
    // content file
    // Headline: Hirn & Heinrich - der Wissenspodcast des Deutschen Zentrums für Neurodegenerative Erkrankungen e.V. (DZNE) 

    // KO! Hirn & Heinrich …
    return $this->headline()->excerpt(50)->or('Hilfsangebot');
    
    // OK! Hirn & Heinrich …
    // return $this->headline()->or('Hilfsangebot');
}

So the output of $this->headline() is not escaped until adding →escape(). OK!

But when create an excerpt, the output is unexpectedly escaped.

As far i can see, its the method, that transform the content

mmh, what do you think? Is that a bug because it’s inconsistent?

  • $this->headline() unescaped output is expected: OK!
  • $this->headline()->excerpt(50) unescaped output is expected: KO! output is escaped

Should be (if escaped output is wanted):

  • $this->headline()->escape() escaped output is expected: OK!
  • $this->headline()->excerpt(50)→escape() escaped output is expected: Not implemented