Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » How to display Created/Last Published Author

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

Page: 1
Go to End
Author Topic: 486 Views
  • pingu
    Avatar
    Community Member
    75 Posts

    How to display Created/Last Published Author Link to this post

    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!

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: How to display Created/Last Published Author Link to this post

    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"

  • pingu
    Avatar
    Community Member
    75 Posts

    Re: How to display Created/Last Published Author Link to this post

    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.

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: How to display Created/Last Published Author Link to this post

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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: How to display Created/Last Published Author Link to this post

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

    486 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.