Jump to:

23473 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » [solved] variable in content return

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 925 Views
  • lerni
    Avatar
    Community Member
    80 Posts

    [solved] variable in content return Link to this post

    hi there

    i've made a simple gallery and now i wanna be able to insert it per variable in the content field. like in this recipe:

    http://doc.silverstripe.org/doku.php?id=recipes:customising-content-in-your-templates&s=paypal

    return a string for a variable works but returning the galleryitems just prints "ComponentSet".

    update:
    it works now. with the foreach loop i can access the items.

    class GalleryPage extends Page {
       static $db = array(
       );
       static $has_one = array(
       );
       static $has_many = array(
          'GalleryItems' => 'GalleryItem'
       );
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $manager = new ComplexTableField(
             $this,
             'GalleryItems',
             'GalleryItem',
             array(
                'Thumbnail' => 'Thumbnail',
                'Beschreibung' => 'Beschreibung',
                ),
             'getCMSFields_forPopup',
             'PageID = '.$this->ID
          );
          $fields->addFieldToTab("Root.Content.Galerie",$manager);
          
          return $fields;
       }

       static $defaults = array(
          'Content' => '$GalleryPage'
       );
    }
    class GalleryPage_Controller extends Page_Controller {
       public function init() {
          parent::init();
          Requirements::block('jsparty/prototype.js');
       }

       function Content() {
          $content = str_replace('$Visiogallery', $this->BB(), $this->Content);
          return $content;
       }
       function BB() {
          $output = "";
          $output = '<ul class="gallery">';
          $items = DataObject::get("GalleryItem");
          foreach ($items as $item) {
             $output .= '<a rel="b_group" href="' . $item->Bild()->Big()->URL . '" title="' . $item->Beschreibung . '"><img alt="' . $item->Beschreibung . '" src="' . $item->Bild()->Small()->URL . '" /></a>';
             $output .= '<p>' . $item->Beschreibung . '</p>';
          }
          $output .= '</ul>';
          return $output;
       }
    }

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