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.

General Questions  

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

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


Reply

Available BB Code tags

  • Bold Text [b]Bold[/b]
  • Italic Text [i]Italic Text[/i]
  • Underlined Text [u]Underlined[/u]
  • Struck-out Text [s]Struck-out[/s]
  • Coloured text [color=blue]blue text[/color]
  • Alignment [align=right]right aligned[/align]
  • Code Block: Unformatted code block [code]Code block[/code]
  • Email link: Create link to an email address [email]you@yoursite.com[/email]
  • Email link: Create link to an email address [email=you@yoursite.com]Email[/email]
  • Unordered list: Unordered list [ulist][*]unordered item 1[/ulist]
  • Image: Show an image in your post [img]http://www.website.com/image.jpg[/img]
  • Website link: Link to another website or URL [url]http://www.website.com/[/url]
  • Website link: Link to another website or URL [url=http://www.website.com/]Website[/url]

Available BB Code tags

  • Bold Text
    Example: [b]Bold[/b]
  • Italic Text
    Example: [i]Italic Text[/i]
  • Underlined Text
    Example: [u]Underlined[/u]
  • Struck-out Text
    Example: [s]Struck-out[/s]
  • Coloured text
    Example: [color=blue]blue text[/color]
  • Alignment
    Example: [align=right]right aligned[/align]
  • Code Block: Unformatted code block
    Example: [code]Code block[/code]
  • Email link: Create link to an email address
    Example: [email]you@yoursite.com[/email]
  • Email link: Create link to an email address
    Example: [email=you@yoursite.com]Email[/email]
  • Unordered list: Unordered list
    Example: [ulist][*]unordered item 1[/ulist]
  • Image: Show an image in your post
    Example: [img]http://www.website.com/image.jpg[/img]
  • Website link: Link to another website or URL
    Example: [url]http://www.website.com/[/url]
  • Website link: Link to another website or URL
    Example: [url=http://www.website.com/]Website[/url]
Avatar
martbarr

Community Member, 54 Posts

8 July 2014 at 8:32am

I normally add some footer tabs to my home page and write a getter....

Avatar
okotoker

Community Member, 41 Posts

7 July 2014 at 5:44am

Usually for something like this, I would just use ModelAdmin. Easier and clearer I think. For a client going into a sponsors section makes more sense than going into settings.

Avatar
camfindlay

Forum Moderator, 228 Posts

25 June 2014 at 9:41pm

Yep I believe you are doing it correctly, I have just tried the code on a fresh 3.1.x core code and got it to work.

Here is my code example + a few changes as to how I would have approached it. Let me know if you have any questions.

https://gist.github.com/camfindlay/af531b60502888b07529#file-customsiteconfig-php-L13

Avatar
Jaymonkey

Community Member, 10 Posts

25 June 2014 at 8:13pm

Hey Camfindlay,

Thanks for your suggestion, the .yaml file is correctly indented and I did rebuild and flush! Still no joy here!

I was wondering if I am trying to access the data in the template the correct way?

Thanks,

Jason

Avatar
camfindlay

Forum Moderator, 228 Posts

25 June 2014 at 5:27pm

Something to check would be to ensure your yaml config file is using 2 spaces indentation and that you have build the database with dev/build and run a flush.

Avatar
Jaymonkey

Community Member, 10 Posts

24 June 2014 at 9:51am

Hi,

I am trying to create some site wide content which will reside in the footer area of my site. I have created a DataExtension to extend siteconfig, which includes a DataObject as this is basically for sponsor images and you need to be able to add and remove as many as necessary.

From the backend I seem to have everything working, but don't seem to be able to access the data through the template, here is my code:

CustomSiteConfig.php

<?php
class CustomSiteConfig extends DataExtension {

private static $has_many = array(
'Sponsors' => 'Sponsor'
);

public function updateCMSFields(FieldList $fields) {

$config = GridFieldConfig_RelationEditor::create();

$config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
'Link' => 'Link'
));

$sponsorfield = new GridField(
'Sponsors',
'Sponsor',
new DataList('Sponsor'),
$config
);

$fields->addFieldToTab('Root.Main', $sponsorfield);
}

}

?>

Sponsor.php

<?php
class Sponsor extends DataObject {

static $db = array (
'Link' => 'text',
);

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

public function getCMSFields() {
$sizeMB = 2; // 2 MB
$size = $sizeMB * 1024 * 1024; // 2 MB in bytes

$uploadField = new UploadField('Image', 'Sponsor Image');

$uploadField->getValidator()->setAllowedMaxFileSize($size);

$fields = new FieldList(
new TextField('Link'),
$uploadField
);

return $fields;
}
}

?>

I have also updated the file in /framework/_config/config.yml to read:

SiteConfig:
extensions:
- CustomSiteConfig

In my template I am trying to access the data like this:

<% loop $SiteConfig.Sponsors %>

<p>$Link</p>

<% end_loop %>

Unfortunately this is not working for me, any ideas anyone?

Many Thanks