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.

Archive

Our old forums are still available as a read-only archive.

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

SideBar images


Go to End
Reply

13 Posts   2603 Views

Avatar
mhull

23 November 2008 at 12:18am Community Member, 79 Posts

I have a sidebar working using the following code:

class Page extends SiteTree {
static $db = array(
'Sidebarcontent' => 'HTMLText'
);
static $has_one = array(
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Sidebar', new TextareaField('Sidebarcontent'), 'HTMLText');

return $fields;
}
}

This is placed in the sidebar page using $Sidebarcontent.XML

I want to be able to put images in here as well, but currently when I try this it just places the link.

Can anyone help me make the sidebar display text and images?

Avatar
Liam

23 November 2008 at 8:44am Community Member, 470 Posts

You'd probably want to use an htmleditorfield for the sidebar, since you're setting it up that way in the db creation and then you can use tinymce to format it.

$fields->addFieldToTab('Root.Content.Sidebar', new HtmlEditorField('Sidebarcontent', 'Sidebar Content'));

Then call it as $Sidebarcontent

Avatar
mhull

23 November 2008 at 9:41am Community Member, 79 Posts

Thanks for your help, I have edited it to the following:

class Page extends SiteTree {
static $db = array(
'Sidebarcontent' => 'HTMLText'
);
static $has_one = array(
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Sidebar', new HtmlEditorField('Sidebarcontent', 'SidebarContent'));

return $fields;
}
}

But it is showing the HMTL as code. What do I do from here? How would I go about using tinymce to format it?

Avatar
jam13

23 November 2008 at 10:16am 121 Posts

Are you using $Sidebarcontent in the template, or $Sidebarcontent.XML?

Avatar
mhull

23 November 2008 at 10:18am Community Member, 79 Posts

I have tried both, and have now changed it to $Sidebarcontent

Avatar
mhull

23 November 2008 at 12:46pm Community Member, 79 Posts

How do I use tinymce to format it?
I cant work out how to get the images and text to show properly.

Avatar
mhull

23 November 2008 at 11:48pm Community Member, 79 Posts

I am really stuck on this, can anyone help?
why is the code not formatting properly? no styles or images are showing

Avatar
jam13

24 November 2008 at 3:31am 121 Posts

Can you clarify exactly what you are seeing rendered on the page?

If the field is an HTMLText field, you edit it in the backend using an HtmlEditorField (using TinyMCE) and display it in the template using a single tag (e.g. $Sidebarcontent) then it should work fine.

Go to Top