Title of new post loses formatting and reverts to the slug

A small thing I’ve been trying to work out for a while now - in just one section of my site, if create a new post, the Title field loses it’s formatting, and shows the slug instead. So Title with spaces and Capital Letters becomes title-with-spaces-and-capital-letters.

Presumably there is something in my setup (in a blueprint?) that’s causing this?


I’ve only seen this happen when a field called title is defined in the blueprint.

Thanks, I’ve checked the blueprint, and ‘title’ isn’t used again. One thing I did notice is that new drafts are completely blank. In other sections where this doesn’t happen the draft file has all the field names ready (even though only the title is the only one filled in). Only after I correct the title and save do the fields appear in the content file. Not sure if this is relevant?

This is the blueprint for the pages:

title: Journal Post
num: date
icon: 🖋
status:
  draft:
    label: Draft
  unlisted:
    label: In Review
  listed:
    label: Published
tabs:
  content:
    icon: text
    columns:
      - width: 2/3
        fields:
          text:
            type: textarea
            label: Description
            size: large
      - width: 1/3
        fields:
          date:
            type: date
            time: true
            default: now
          mainimage:
            label: Masthead
            type: files
            layout: cards
            link: false
            image:
              back: white
          thumb:
            label: Thumbnail
            type: files
            layout: cards
            link: false
            image:
              back: white
          tags:
            label: Tags
            type: tags
  assets:
    icon: image
    sections:
      assets:
        type: files
        size: small
        layout: cards
        image:
          ratio: 1/1
          back: white
  seo: tabs/seo

Hey Mr. Hicks,

have you checked the seo blueprint? Looks like extended your journal blueprint with it.

Thanks David, it was worth a look, but it only has two fields. No reserved names are used. I tried a new post with that part of the blueprint removed, just to double check.

Your blueprint looks absolutely fine.

What’s your Kirby version? Which plugins do you have installed? And could you please post the blueprint with the section from which you add these new posts?

Thanks Sonja, here’s that info!

Kirby 3.9 (although it’s been an issue for a long time, possibly since a created the site afresh with Kirby 3.0)

Plugins installed are:

  • custom-tags
  • fastpage
  • gallery (left over from the starterkit)
  • kirby-chopper
  • kirby-color-master
  • kirby3-feed
  • kirby3-fingerprint
  • kirby3-xmlsitemap
  • previews

There are two sections from which I add posts. First the dashboard (site.yml):

title: Site
tabs:
  content:
    icon: text
    columns:
        - width: 2/3
          sections:
            pages:
              headline: Sections
              type: pages
              create: default
              layout: cards
              image:
                ratio: 1/1
                size: small
              templates:
                - home
                - work
                - about
                - shop
                - journal
                - troika
                - default
                - eggs
                - wildlife
        - width: 1/3
          sections:
            Drafts:
              headline: Journal Drafts
              type: pages
              create: post
              parent: site.find("journal")
              template: post
              status: draft
              flip: true
              info: "{{ page.date.toDate('d M Y') }}"
            Troika:
              headline: Troika Drafts
              type: pages
              parent: site.find("troika")
              template: episode
              status: draft
              flip: true
              info: "{{ page.date.toDate('d M Y') }}"
  meta:
    label: Meta
    fields:
      heading:
        type: text
        label: Main Site Heading
      strapline:
        type: textarea
        label: Strapline
  seo: tabs/seo

And then the journal section:

title: Journal
num: date
icon: 🏠

tabs:
  posts:
    columns:
      - width: 2/3

        sections:
          Published:
            type: pages
            template: post
            status: listed
            flip: true
            layout: cards
            image:
              back: white
              ratio: 2/1
              cover: true
            info: "{{ page.date.toDate('d M Y') }}"

      - width: 1/3
        sections:
          Drafts:
            type: pages
            status: drafts
            create: post
            template: post
            flip: true
            info: "{{ page.date.toDate('d M Y') }}"

  archive:
    sections:
      years:
        extends: sections/years
        parent: page.find("archive")

And here’s the SEO tab that I’m adding to the new posts:

label: SEO bollocks
icon: search
columns:
  - width: 2/3
    fields:
      seoDescription:
        label: Description
        type: textarea
        buttons: false
  - width: 1/3
    fields:
      socialimage:
        label: Social Share Image
        type: files
        help: Used for Twitter and Facebook
        layout: cards
        link: false
        image:
          back: white

Do you use any hooks in your config.php?

If not, i would try to deactivate each plugin and try so create a page without them.

Or just wait for sonjas answer :wink:

Ah, now I’m getting somewhere! I’ve got two models for the Journal section, and it’s posts. I think this is something Bastian implemented when he helped me migrate my site to Kirby. This is using the ‘fastpage’ plugin.

In the site/models/post.php I have:

<?php

use Kirby\Cms\Template;

class PostPage extends FastPage
{
    const TEMPLATE = 'post';

    public function cover()
    {
        if ($image = $this->content()->thumb()->toFile()) {
            return $image;
        }

        if ($image = $this->content()->mainimage()->toFile()) {
            return $image;
        }

        // take whatever is the first image
        return $this->image();
    }

}

If I remove the contents of that file it all works as it should. I wonder if I still need this? I can’t find any information about the fastpage plugin, and I’m not entirely sure what this file does.

If you delete the file, your frontend might break, becaue the cover method is then no longer defined.

What is in the FastPage plugin?

There are only 3 files in there, I’ve uploaded them to Dropbox:

Most of them don’t look as if they contain anything likely to cause trouble, but this one does mention the slug:

<?php

use Kirby\Cms\Template;

class FastPage extends Page
{
    const TEMPLATE = 'default';
    const CHILD_MODEL = null;
    const CHILD_TEMPLATE = 'default';

    public function __construct(array $props)
    {
        if (empty($props['slug']) === true) {
            throw new Exception('The slug is required');
        }

        $this->propertyData = $props;

        $this->slug    = $props['slug']    ?? null;
        $this->dirname = $props['dirname'] ?? null;
        $this->root    = $props['root']    ?? null;
        $this->parent  = $props['parent']  ?? null;
        $this->site    = $props['site']    ?? site();
        $this->isDraft = $props['isDraft'] ?? false;

        $this->setNum($props['num'] ?? null);
    }

    public function intendedTemplate()
    {
        return $this->intendedTemplate = $this->intendedTemplate ?? new Template(static::TEMPLATE);
    }

    public function inventory(): array
    {
        if ($this->inventory !== null) {
            return $this->inventory;
        }

        $kirby = $this->kirby();

        $inventory = FastDir::inventory(
            $this->root(),
            $kirby->contentExtension(),
            $kirby->contentIgnore(),
            $kirby->multilang()
        );

        foreach ($inventory['children'] as $index => $child) {
            $inventory['children'][$index]['model']    = static::CHILD_MODEL;
            $inventory['children'][$index]['template'] = static::CHILD_TEMPLATE;
        }

        return $this->inventory = $inventory;
    }

    public function isReadable(): bool
    {
        return true;
    }

    public function template()
    {
        return $this->intendedTemplate();
    }

}

Hm, this plugin extends existing classes, but from the plugin itself I can’t tell why this was needed and if it is still needed.

Thanks Sonja, for now I’ve bypassed the plugin by changing:

class PostPage extends FastPage

to just…

class PostPage extends Page

in the models/post.php file. Everything works as it should, including the post title. Thanks for helping me find the cause!