Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Looping out images in template [SOLVED]

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

Page: 1
Go to End
Author Topic: 797 Views
  • jocken
    Avatar
    Community Member
    3 Posts

    Looping out images in template [SOLVED] Link to this post

    I'm struggling hard with SilverStripe 3.0 because the documentation doesn't exist yet.

    I wan't to attach multiple images to a Page. It was extremely easy to add the cms-part but I can't loop it out.

    Page.php

    <?php

    class SlidePage extends SiteTree {

       public static $db = array(
       );

       public static $has_many = array(
          'Photo' => 'Image'
       );
          
       public function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab("Root.Images", new UploadField('Photo'));

    return $fields;
    }   

    }
    class SlidePage_Controller extends ContentController {

       public static $allowed_actions = array (
       );

       public function init() {
          parent::init();

       }

    }
    ?>

    This gives me the ability to attach images to a slidepage but I don't know how to loop it out. I really like the simplicity to add and remove images so I don't want to change anything there. Just need help with showing it.

  • thi3r
    Avatar
    Community Member
    25 Posts

    Re: Looping out images in template [SOLVED] Link to this post

    what about something like this:

    <% if Photo %>
    <% loop Photo %>
    <img src="$URL" alt="$Title" />
    <% end_loop %>
    <% end_if %>

  • jocken
    Avatar
    Community Member
    3 Posts

    Re: Looping out images in template [SOLVED] Link to this post

    Seriously? It was that easy? There should be some documentation about this. Anyways, BIG thank you. Worked like a charm!

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