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.

General Questions /

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

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

Edit content in sidewide sidebar


Go to End


6 Posts   1279 Views

Avatar
Kim K

Community Member, 8 Posts

13 October 2014 at 6:08am

Hi

I have a SS site with two sidebars. The sidebars are commen for all the sites pages. Some of the content blocks in both sidebars should be editable via the cms.

What is the way to do this?

I think I have to make a ContentBlockPage with:
Class ContentBlocksPage extends Page{
private static $db = array(
'Content1' => 'HTMLText',
'Content2' => 'HTMLText'
);

public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new HTMLEditorField(' Content1',), 'Content');
$fields->addFieldToTab('Root.Main', new HTMLEditorField(' Content2',), 'Content');
return $fields;
}
}
Class ContentBlocks_Controller extends Page_Controller{
}

If I do this I still have the ordinary content field in the sitetree in db.

And how do I get the db-data into my sidebars, which now is static include-files. I can use $Content1 in the ss-files. But where is the connection to the db?

Maybe this not the right approch at all, this must be a common problem. I have tried to search for a solution, but I couldn't find one.

Any suggestions?

Avatar
camfindlay

Forum Moderator, 267 Posts

13 October 2014 at 10:47am

Hi there...

this is one of the useful things with SilverStripe and makes getting your page types set up quick and easy. As long as you keep the naming conventions in your "Model" (the ContentBlocksPage) $db and when you create the fields in "getCMSFields" you don't have to specify any database connection when you want to use the content stored in your templates. As you mention, $Content1 and $Content2 will be able to be used in your *.ss templates.

If you have included your sidebar in a template "Include" you will also have to make sure to call the include into your main template file using...

 <% include NameOfInclude %>

You would replace "NameOfInclude" with what you have called your file. Note you do not need to put the .ss file extension on.

Hope that helps.

Avatar
Kim K

Community Member, 8 Posts

13 October 2014 at 8:26pm

Cant get it to fully work. I have the right data in the db, but I cant get them out in my ss-file

My Page.php:

<?php
class Page extends SiteTree {

private static $has_one = array(
);

private static $allowed_children = array(
'ContentBlockPage'
);

}
class Page_Controller extends ContentController {
private static $allowed_actions = array (
);

public function init() {
parent::init();
}
}

My ContentBlockPage.php:

<?php
class ContentBlockPage extends Page {

private static $db = array(
'Tilbud' => 'HTMLText'
);

public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new HTMLEditorField('Tilbud', 'Skriv dit tilbud:'), 'Content');
return $fields;
}

private static $has_one = array(
);

}
class ContentBlockPage_Controller extends Page_Controller {

}

I tried with and without(in Page.php) :
private static $allowed_children = array(
'ContentBlockPage'
);

When I open a ss-page based on page.php I try:

$ContentBlockPage.Tilbud

and

$Tilbud

But they are both empty(and the html is in the db).

What have I missed?

Avatar
camfindlay

Forum Moderator, 267 Posts

14 October 2014 at 8:55am

Edited: 14/10/2014 8:56am

It might pay to go back over the tutorial at http://doc.silverstripe.org/framework/en/tutorials/2-extending-a-basic-site - I have a feeling you've not quite picked up the way SilverStripe structures things. That tutorial provides some good diagrams of how things work.

$allowed_children only refers to page types that can be nested under other page types in the SiteTree section of the CMS UI.

If you want to access "$Tilbud" in your examples then you must set the page type to "ContentBlockPage", if you want to access "$Tilbud" from a "Page" page type then you will need to loop over the Child pages in your template as such:

../Layout/Page.ss

<% loop $Children %>
    $Tilbud
<% end_loop %>

Anyway, as I say, suggest going over that tutorial.

Avatar
Nobrainer Web

Community Member, 138 Posts

15 October 2014 at 10:17am

Edited: 15/10/2014 10:20am

Dejligt at se endnu en dansker på vej på silverstripe vognen :-)

Hope you figure it out, SilverStripe is a great system - ask if you need more help.
Also be sure to check out the irc channel

Btw, you might want to have a look at using a custom siteconfig extension. That is where i keep all sitewide info.

Avatar
Kim K

Community Member, 8 Posts

28 October 2014 at 7:31pm

Hi Thanks for the help.

I used the proposal fram Nobrainerweb:

mysite/code:

new class:

<?php
class CustomSiteConfig extends DataExtension {
private static $db = array(
'Tilbud' => 'HTMLText',
'Forvirksomheder' => 'HTMLText',
'Forklubber' => 'HTMLText',
'Forprivate' => 'HTMLText',
'Forplejehjem' => 'HTMLText'
);
public function updateCMSFields(FieldList $fields) {
$fields->addFieldToTab("Root.Tilbud", new HTMLEditorField("Tilbud", "Tilbud"));
$fields->addFieldToTab("Root.ForVirksomheder", new HTMLEditorField("Forvirksomheder", "For virksomheder"));
$fields->addFieldToTab("Root.ForKlubber", new HTMLEditorField("Forklubber", "For klubber"));
$fields->addFieldToTab("Root.ForPrivate", new HTMLEditorField("Forprivate", "For private"));
$fields->addFieldToTab("Root.ForPlejehjem", new HTMLEditorField("Forplejehjem", "For plejehjem"));
}
}

AND added to the bottom of mysite/_config/config.yml:

SiteConfig:
extensions:
- CustomSiteConfig

Then dev/build + flush

and I have new HTML-text tabs in "Settings".

The text in the new tabs I can use sitewide in templades as e.g.: $SiteConfig.Forvirksomheder

Nice!