Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Set image width in SiteConfig


Reply


3 Posts   899 Views

Avatar
shrike

Community Member, 15 Posts

17 October 2011 at 7:47am

I tried to control templates main image width by customizing SiteConfig and added there data field for number. Now I'd like to read this number in template like this:

<div class="MainImage">$MainImage.SetWidth($SiteConfig.MainImageMaxWidth)</div>

But, that does not seem to work. My CustomSiteConfig goes like this:

<?php

   class CustomSiteConfig extends DataObjectDecorator {
   
      function extraStatics() {
         return array(
            'db' => array(
            'MainImageMaxWidth' => 'Int',
         )
      );
   }

   public function updateCMSFields(FieldSet &$fields) {

$fields->addFieldToTab("Root.Main", new TextField('MainImageMaxWidth', _t('SiteConfig.MAXMAINIMAGEWIDTH','Set maximum width for main image in template')));

}
}

What I did wrong?

Avatar
shrike

Community Member, 15 Posts

18 October 2011 at 4:15am

I found another post from forum: [url]http://www.silverstripe.org/template-questions/show/11731[/url]

I think I have a same kind of problem: can not use variables...

Avatar
swaiba

Forum Moderator, 1805 Posts

18 October 2011 at 4:57am

And this is my stock answer to using a variable as a param...
http://www.silverstripe.org/template-questions/show/13619#post290481