Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » SideBar images

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

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

Page: 1 2
Go to End
Author Topic: 2473 Views
  • mhull
    Avatar
    Community Member
    79 Posts

    SideBar images Link to this post

    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?

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: SideBar images Link to this post

    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

  • mhull
    Avatar
    Community Member
    79 Posts

    Re: SideBar images Link to this post

    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?

  • jam13
    Avatar
    121 Posts

    Re: SideBar images Link to this post

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

  • mhull
    Avatar
    Community Member
    79 Posts

    Re: SideBar images Link to this post

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

  • mhull
    Avatar
    Community Member
    79 Posts

    Re: SideBar images Link to this post

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

  • mhull
    Avatar
    Community Member
    79 Posts

    Re: SideBar images Link to this post

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

  • jam13
    Avatar
    121 Posts

    Re: SideBar images Link to this post

    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.

    2473 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.