Trouble rendering variable on template

Silverstripe Version: 5.3

What could be the reason that a variable isn’t rendering?

I loop over a DataObject and everything except one variable renders. There is no misspelling and it is definitely in the database.

Document.php:

private static $db = [
        'Title' => 'Varchar',
        'ShortLinkTitle' => 'Varchar',
        'Author' => 'Varchar',
        'SortOrder' => 'Int'
    ];
...
$fields = FieldList::create(
...
TextField::create('ShortLinkTitle', "Short title for link of document e.g. 'Agenda' (actual document name longer)"),
  TextField::create('Author', "Author of document"),
...
)

template:

<span class="short-link-title">$ShortLinkTitle</span>
<% if $Author %>
     <span class="author">$Author</span>
<% end_if %>

image

I never had this issue before.
Has anybody else and can point me into the right direction, please?

1 Like

Pedantic addendum: you can loop over a DataList, not over a DataObject.

The template and the HTML fragment you posted do not match: I’m expecting a blank line and a 5 space indentation before the author span, so my guess is you are not rendering that template.

Hi ntd,
Yes, sorry, DataList :wink:.
Thank you for your reply, but I don’t understand it.

What I don’t understand is the fact, that the <% if $Author %>
is obviously true, otherwise the span line with the class “author” wouldn’t be showing, so there is a mismatch and I have absolutely no idea why this is.
If there were no Author, then the span line wouldn’t appear.

I definitely render this template. I tested it by swapping the two.

It just dawned on me that Author is a special word, so googled it and according to this post it is: Can not get property of page to show on Template

1 Like