lessons/v4/adding-custom-fields-to-a-page having issues with a varchar value not displaying.

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

Silverstripe Version:
SS4.3
Question:
Struggling to get $Author to display only displaying blank value even though the database is holding a value. Could anybody possibly tell me why I am not able to call this variable from the database?
Details of query:
I am new to SilverStripe and have been working through the lessons. I am on lesson 6 “Adding custom fields to a page”. I’ve updated the “ArticlePage” class to generate the fields in the database and use the “FieldList” API to add some new form inputs.
No issues displaying $Date and $Teaser but $Author isn’t working. I’ve checked the GitHub repository to compare my code but unfortunately even though the “Tutor” tells you to use $Author to replace static values he/she hasn’t gone as far as to do the same.

ArticlePage.php

<?php
namespace SilverStripe\Lessons;

use Page;
use SilverStripe\Forms\DateField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\TextField;

class ArticlePage extends Page
{
  private static $can_be_root = false;

  private static $db = [
    'Date' => 'Date',
    'Teaser' => 'Text',
    'Author' => 'Text',
  ];
  public function getCMSFields()
  {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Main', DateField::create('Date','Date of article'),'Content');
    $fields->addFieldToTab('Root.Main', TextareaField::create('Teaser')
      ->setDescription('This is the summary that appears on the article list page.')
      ,'Content');
    $fields->addFieldToTab('Root.Main', TextField::create('Author','Author of article'),'Content');

    return $fields;
  }
}

ArticlePage.ss

...//
			<!-- BEGIN MAIN CONTENT -->
			<div class="main col-sm-8">

				<h1 class="blog-title">$Title</h1>

				<div class="blog-main-image">
					<img src="http://placehold.it/765x362" alt="" />
					<div class="tag"><i class="fa fa-file-text"></i></div>
				</div>

				<div class="blog-bottom-info">
					<ul>
						<li><i class="fa fa-calendar"></i> $Date.Long </li>
						<li><i class="fa fa-comments-o"></i> 3 Comments</li>
						<li><i class="fa fa-tags"></i> Properties, Prices, best deals</li>
					</ul>

					<div id="post-author"><i class="fa fa-pencil"></i> By $Author</div>
				</div>

				<div class="post-content">
					<div class="highlight-bold">$Teaser</div>

					<div class="divider"></div>
//...

The code looks fine, although it might make more sense to use Varchar for Author rather than Text. Is it possible you just need to publish the page?

In addition to @JonoM’s answer, just in case, add ?flush to the end of the URL when you view the page. Especially if your site is in dev mode, template caches sometimes get in the way.

Thank you. Sorry the datatype Text was meant as a test and got snucked in when I copied it to this post.
I’ve definitely published the page.

Yeah I’ve been using ?flush and /dev/build on regular intervals.

I’ve tested my code by including another field to ArticlePage.php to “replace” Author with Publisher. This seemed to work. So I am drawing a conclusion that the field name Author is not allowed to be used. For my sanity sake if anybody has an idea of why this is happening I would be thankful.

private static $db = [
‘Date’ => ‘Date’,
‘Teaser’ => ‘Text’,
‘Author’ => ‘Varchar’,
‘Publiser’ => ‘Varchar’,
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab(‘Root.Main’, DateField::create(‘Date’,‘Date of article’), ‘Content’);
$fields->addFieldToTab(‘Root.Main’, TextareaField::create(‘Teaser’)
->setDescription(‘This is the summary that appears on the article list page.’),
‘Content’
);
$fields->addFieldToTab(‘Root.Main’, TextField::create(‘Author’,‘Author of article’),‘Content’);
$fields->addFieldToTab(‘Root.Main’, TextField::create(‘Publiser’,‘Publiser of article’),‘Content’);

return $fields;

}

I had the exact same issue and finally just gave up. Definitely something up with using ‘Author’ but I couldn’t get to the bottom of it.
Kind of difficult to “hop on the SilverStripe train” when the lessons don’t work as expected and there are thousands of pages of outdated documentation and articles out there. I’m questioning if SilverStripe is the way to go. I want to give it the benefit of the doubt, but struggling daily.

SS 4.7
Same problem, changing Author to Published didn’t help
And secont problem - https://www.silverstripe.org/learn/lessons/v4/adding-custom-fields-to-a-page-1

String as DataType in not allowed

I had problems last year, when I tried to follow the tutorials, I found watching the v3 videos helped. See my blog for details: Setup a new SilverStripe 4 Project [ Pen y Fan ]

You can see a branch for each lesson on Github: GitHub - Pen-y-Fan/silverstripe-lessons: SilverStripeCMS Lessons

I hope this helps, once you get your head around SilerverStripe it is great.

Here’s two possibilities I can think of.

  1. To ensure it’s not a clashing namespacing issue. Try dev/building with:

private static $table_name = 'ArticlePage';

  1. I recall having issues with varchar DB types when not specifying the size. I’m not sure if that’s a PHP7 thing, SilverStripe or maybe just my memory playing up.

‘Author’ => ‘Varchar(100)’,

Had the same problem… Author value was persisting correctly in the CMS and DB, just resulting in a blank string when trying to use the template var.

Only way I was able to get it working was to not use $Author or $Publisher (note Yoda-Soda was using ‘Publiser’), so presuming they’re reserved in some way, even after implementing @James 's suggestions.

I ended up with:

private static $table_name = 'ArticlePage';

and, for my DB fields:

private static $db = [
   'Date' => 'Date',
    'ArticleAuthor' => 'Varchar(100)',
    'Teaser' => 'Text',
];

I can confirm this.
Happened to me too in the lessons.
Author was the culprit, although I still do not know why