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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Set image width in SiteConfig


Go to End


3 Posts   1911 Views

Avatar
shrike

Community Member, 17 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, 17 Posts

18 October 2011 at 4:15am

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

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

Avatar
swaiba

Forum Moderator, 1899 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