Jump to:

10931 Posts in 2614 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » Subsites and DataObject error

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 332 Views
  • ROlckers
    Avatar
    Community Member
    8 Posts

    Subsites and DataObject error Link to this post

    I have a page type (ModelDetailPage) which has a data object (ModelDetailPageGallery) associated via the data object manager. I'm also using the subsites module.

    I have a couple of subsites (e.g. testsite.testdomain.com, testsite2.testdomain.com) and a Main Site subsite (e.g. www.testdomain.com). I have a couple of subsite virtual page links in the subsites linking to pages in the Main Site subsite. This is purely to link up similar content across all subsites. So the Main Site has a page called Model which is of ModelDetailPage page type. This page has a couple of ModelDetailPageGallery items associated with it.

    Now for the error. When I view the subsite page (www.testdomain.com) I get an error if I use an <% IF %> statement around the <% control ModelDetailPageGallery %> statement inside the template. It does work if I don't call it through the subsite virtual page links and call it as an actual page on the subsite. It does actually work if I don't use the <% IF %> and just use the <% control %>, but I'd really like to use the <% IF %> if possible.

    The page:

    <?php
    class ModelDetailPage extends Page {
       
       public static $db = array(
       );
       
       public static $has_many = array(
          'ModelDetailPageGallery' => 'ModelDetailPageGallery'
       );
       
       public function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->removeByName("To-do");
          $fields->removeByName("Access");
          $galleryDOM = new DataObjectManager(
             $this,
             'ModelDetailPageGallery',
             'ModelDetailPageGallery',
             array('Description'=>'Description', 'RRPrice' => 'RR Price', 'getImageURL'=>'Image'),
             'getCMSFields_forPopup'
          );
          $galleryDOM->setAddTitle('a Line-up Item');
          
          $fields->addFieldToTab("Root.Content.LineUp", $galleryDOM);
          
          return $fields;
       }
       
    }
    class ModelDetailPage_Controller extends Page_Controller {
       
    }

    The dataObject:

    <?php

    class ModelDetailPageGallery extends DataObject {
       
       static $db = array (
          'Description' => 'HTMLVarchar(512)',
          'RRPrice' => 'Varchar(50)',
          'DownloadLink' => 'Varchar(1024)'
       );
       
       static $has_one = array (
          'ModelDetailPage' => 'ModelDetailPage',
          'Image' => 'Image'
          
       );
       
       public function getCMSFields_forPopup()   {
          return new FieldSet(
             new FileIFrameField("Image", "Image"),
             new TextField("Description", "Description (HTML allowed)"),
             new TextField("RRPrice", "RR Price"),
             new TextField("DownloadLink", "Download Link")
          );
       }
       
       public function getImageURL() {
          return '<img src="'.$this->Image()->Filename.'" width="80px" />';
       }
       
    }

    SortableDataObject::add_sortable_class('ModelDetailPageGallery');

    The template:
    (this works)

                <% control ModelDetailPageGallery %>
                <div class="grid_3">
                   <a href="#" class="<% if First %>first_rc<% end_if %>">
                      <img src="<% control Image.SetWidth(150) %>$Link<% end_control %>" alt="$Description" />
                      <h4>$Description</h4>
                      <p class="txt_link"><span class="price_car">$RRPrice</span> RRP</p>
                      <% if DownloadLink %>
                      <span class="txt_link"><span class="arrow_link">&raquo; </span>Download brochure</span>
                      <% end_if %>
                      </a>
                </div>
                <% end_control %>

    (this doesn't)

                <% if ModelDetailPageGallery %>
                <% control ModelDetailPageGallery %>
                <div class="grid_3">
                   <a href="#" class="<% if First %>first_rc<% end_if %>">
                      <img src="<% control Image.SetWidth(150) %>$Link<% end_control %>" alt="$Description" />
                      <h4>$Description</h4>
                      <p class="txt_link"><span class="price_car">$RRPrice</span> RRP</p>
                      <% if DownloadLink %>
                      <span class="txt_link"><span class="arrow_link">&raquo; </span>Download brochure</span>
                      <% end_if %>
                      </a>
                </div>
                <% end_control %>
                <% end_if %>

    Any help or a steer in the right direction would be much appreciated!

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