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>
//...