Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » How to create a generic (editable) content block

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

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

Page: 1 2 3
Go to End
Author Topic: 5269 Views
  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: How to create a generic (editable) content block Link to this post

    Instead of creating a separate page. Just add the custom fields to the homepage (in a separate tab "student of the month tab"). Then use these fields in your template.

  • sonicparke
    Avatar
    74 Posts

    Re: How to create a generic (editable) content block Link to this post

    Thanks for the reply. I'm new to SS and not great at PHP but can fumble my way through usually. How would I add new tabs? I'm assuming I would do that in Page.php and Page.ss.

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: How to create a generic (editable) content block Link to this post

    Add the fields to the homepage class, then stick them in the backend in the function getCMSFields(). Good luck !

    Quick copy-paste , so please don't mind any errors :

    class HomePage extends Page {
    static $db = array(
    "sStudentName" => "Text"
    );

    function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Content.StudentOfTheMonth', new TextField('sStudentName'), 'Content');
    return $fields;
       }

  • sonicparke
    Avatar
    74 Posts

    Re: How to create a generic (editable) content block Link to this post

    OK. This is working out pretty well. I do have a couple of issues though. I need it to be displayed on everypage but when I have the code you gave me in HomePage.php I have to put the putput in HomePage.ss. That works gret for having it on the home page but how do I get it to output to page.ss?

    Also. How do I adjust the text box size for the admin. Is that a CSS thing or is there something else I need to put in the code?

    Thanks! I'm on the right track.

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: How to create a generic (editable) content block Link to this post

    You should be able to put $Page(home).SideBarContent into your Page.ss to get the SideBarContent of the home page put onto every page.

  • sonicparke
    Avatar
    74 Posts

    Re: How to create a generic (editable) content block Link to this post

    OK. I got the larger Text box by using HtmlEditorField rather than TextField. I'm still having issues with outputting it to ever page. Ideally I think having it outpout to an include file would be the best. That's what I really want to do. So I can put a tab on the homepage or create a new page type and go that route. Either way I don't want it only on the Homepage or only on it's own page using a layout template. I trie dputting it in page.php while it works great there it gives me individual content for each page. Which won't work for me.

    Basically I need an include file that's editable from the CMS with 3 input fields:

    1. Student Name
    2. Student Photo (Image field. I got it psuedo working. It uploads but it just won't display the image.
    3. Student Bio (HtmlEditorField)

    Thanks for all the help.

    Edit: I just saw your reply Sam. I will try that although I'm not sure where .SideBarContent is coming from.

    Brad

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: How to create a generic (editable) content block Link to this post

    SideBarContent was what I thought the name of the field was.

    You might want to try this putting this on your Page.ss file - either the layout or the main template, whichever is most logical for where you're positioning the content

    <% control Page(home) %>
    $Title <br />
    $Content <br />
    <% end_control %>

    That piece of code would show the home page's title and content fields on your template, on every page.

    The <% control Page(home) %> ... <% end_control %> syntax tells the system "instead of getting this page's content for this part of the template, get the home page's content."

    By changing $Title and $Content to the fields that you would like to use, you should be able to achieve the effect you're after.

  • sonicparke
    Avatar
    74 Posts

    Re: How to create a generic (editable) content block Link to this post

    Brilliant! That did it! Thanks, Sam!

    Now all I have to figure out is why the image field isn't working. I'm liking SS a lot so far. Thanks!

    5269 Views
Page: 1 2 3
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.