Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How to display Created/Last Published Author


Go to End


5 Posts   1774 Views

Avatar
pingu

Community Member, 75 Posts

30 May 2013 at 5:40am

Edited: 30/05/2013 5:40am

I may be missing something, but I can't find a way to display the name of a page's author or publisher.

I need to include the following byline on the footer of each page:
"Page last updated by [Author] on $LastEdited"

What is the cleanest way to achieve this? Thank you!

Avatar
Devlin

Community Member, 344 Posts

31 May 2013 at 12:32am

class Page extends SiteTree{
	static $has_one = array(
		'Author' => 'Member',
	);
	function onBeforeWrite() {
		parent::onBeforeWrite();
		$this->AuthorID = Member::currentUserID();
	}
}

"Page last updated by $Author.Firstname $Author.Surname on $LastEdited"

Avatar
pingu

Community Member, 75 Posts

31 May 2013 at 12:21pm

Thanks Devlin.

I was hoping I might be able to use the preexisting versioning information somehow (since its available on the history tab for each page), but I may have to do it this way, since I can't find another working solution.

Avatar
Devlin

Community Member, 344 Posts

31 May 2013 at 7:31pm

Edited: 31/05/2013 7:41pm

Well as you mentioned it. You could do this without any php modifications:

"Page last updated by $allVersions.First.Author.Surname on $LastEdited"

But I think the first solution is cleaner. (edit: -- since I like to truncate the versions table once in a while.)

Avatar
Willr

Forum Moderator, 5523 Posts

2 June 2013 at 2:59pm

Pretty sure you can just do $Author.Name to get any page author's name.