Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Get a custom collection from a page retrieved with DataObject::get

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

Page: 1
Go to End
Author Topic: 329 Views
  • nomadic
    Avatar
    Community Member
    2 Posts

    Get a custom collection from a page retrieved with DataObject::get Link to this post

    I have a collection of images within a custom page class, that represents a project and its associated images.

    For the front page - I would like to show the first image from each project within a slider. The only issue I have is how to get to the images!

    I started with this code in the controller :

       public function ProjectPageList($limit=6){
          $start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
          $list = DataObject::get("ProjectPage", "", "Created DESC","","$start , $limit");
          return $list;
       }


    And then in the view:
    <% loop ProjectPageList %>

       <li>
          <a href="$Link">
          <% control getGalleryImages(1) %>
       <img src="$Image" alt="$Title" />
    <% end_control %>
          </a>
          <a class="inspiration" href="/your-inspiration/"><div>See more inspiration</div></a>
          <a class="viewkitchen" href="$Link"><div>View this kitchen</div></a>
       </li>   
    <% end_loop %>

    A shove in the right direction would be appreciated!

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Get a custom collection from a page retrieved with DataObject::get Link to this post

    How have you linked to the images in your DataModel? Do you have a relation (like a $has_many) to the images?

    If that is the case then the ORM handles all the queries for you and you can just include <% loop Images %>.. in your template.

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