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.

Archive /

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

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

SideBar images


Go to End


13 Posts   3660 Views

Avatar
mhull

Community Member, 79 Posts

23 November 2008 at 12:18am

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

Community Member, 470 Posts

23 November 2008 at 8:44am

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

Community Member, 79 Posts

23 November 2008 at 9:41am

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

121 Posts

23 November 2008 at 10:16am

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

Avatar
mhull

Community Member, 79 Posts

23 November 2008 at 10:18am

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

Avatar
mhull

Community Member, 79 Posts

23 November 2008 at 12:46pm

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

Avatar
mhull

Community Member, 79 Posts

23 November 2008 at 11:48pm

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

Avatar
jam13

121 Posts

24 November 2008 at 3:31am

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