Jump to:

3445 Posts in 1031 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » Retreiving Data Model inside a Template

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

Page: 1
Go to End
Author Topic: 366 Views
  • Ajaxian
    Avatar
    Community Member
    8 Posts

    Retreiving Data Model inside a Template Link to this post

    Hi All,

    I've 3 models A has_many B, B has_many C; B has_one A, C has_one B

    In a template file I can get all C models/instances. But I only can address the attributes of C, I can't get Attributes of the B instance with which A has a has_one relationship.

    The only way I see is to have a method in C model:
    public function getNameofB() {
    return B::get()->get_ByID($this->BID)->Name
    }

    But is there another way of doing this. ?

    Thanks

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Retreiving Data Model inside a Template Link to this post

    You can use <% loop %> and <% with %> on relations so from C you can do - <% with B %>$Name<% end_with %>..

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