Jump to:

5523 Posts in 1734 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » siteconfig dom logos

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

Page: 1
Go to End
Author Topic: 422 Views
  • Guy Van Bael
    Avatar
    Community Member
    32 Posts

    siteconfig dom logos Link to this post

    Hi,

    I'm trying to add dom to siteconfig (ss2.4.7) that holds logo's which have to be visible on every page. All goes well.
    I created logo.php, CustomSiteConfig.php and so i can add logo's and their description to the siteconfig. To test, i added 2 of them.

    The problem starts when i want to display the logo's in the template
    in the include file is

    <div id="logos">
          <% control SiteConfig.Logos %>
                   <p>$SiteConfig.description</p>
          <% end_control %>
       </div>

    When i display the page in the browser, i can see in the pagesource that i finds 2 records (2 times p tag). However. It doesn't display the description from the database. Tried to display the logo itself (which is the final goal) using $SiteConfig.LogoImage and $SiteConfig.LogoImage.URL, but no luck.

    solution anyone?

    This is the code for CustomSiteConfig.php

    <?php

    class CustomSiteConfig extends DataObjectDecorator {

    function extraStatics() {
    return array(
    'db' => array(
    'Headertext' => 'HTMLText'
    ),
    'has_many' => array(
    'Logos' => 'Logo'
    )
    );
    }
    public function updateCMSFields(FieldSet &$fields) {

    $manager = new SiteConfig_DataObjectManager(
    $this->owner,
    'Logos',
    'Logo',
    array('LogoImage' => 'logo',
    'description' => 'Omschrijving'
    ),
    'getCMSFields_forPopup'
    );
    $manager->setParentClass("SiteConfig");
    $manager->setSourceID($this->owner->ID);
    $fields->addFieldToTab("Root.logos", $manager);

    }
    }
    class SiteConfig_DataObjectManager extends DataObjectManager {
    function setSourceID($val) {
    if (is_numeric($val)) {
    $this->sourceID = $val;
    }
    }
    function sourceID() {
    if (isset($this->sourceID) && $this->sourceID !== null && is_numeric($this->sourceID)) {
    return $this->sourceID;
    }
    return parent::sourceID();
    }
    }

    this is Logo.php

    <?php

    class Logo extends DataObject
    {
    static $db = array (
    'description' => 'Text'
    );

    static $has_one = array (
    'SiteConfig' => 'SiteConfig',
    'LogoImage' => 'Image'
    );

    public function getCMSFields_forPopup()
    {
    return new FieldSet(
    new TextField('description'),
    new FileIFrameField('LogoImage')
    );
    }
    }

    ?>

  • Guy Van Bael
    Avatar
    Community Member
    32 Posts

    Re: siteconfig dom logos Link to this post

    Found the solution: Seems like you have to leave out the Siteconfigbit when adressing dom-fields related to the siteconfig

    this is the new code for the templateinclude

    <div id="logos">
          <% control Siteconfig.Logos %>
                   <p>$LogoImage</p>
          <% end_control %>
       </div>

  • martimiz
    Avatar
    Forum Moderator
    1068 Posts

    Re: siteconfig dom logos Link to this post

    You are right - but this is normal SilverStripe behaviour, so it's not a 'DOM' thing A control structure always iterates a set of DataObjects and within that structure the scope is that of the DataObject.

    In this case <% control SiteConfig.Logos %> loops all Logo objects in Logos, so within the control it's enough to just address its properties

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