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

How to create a generic (editable) content block


Reply

17 Posts   5436 Views

Avatar
Fuzz10

14 November 2007 at 7:26am Community Member, 787 Posts

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.

Avatar
sonicparke

14 November 2007 at 8:03am 74 Posts

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.

Avatar
Fuzz10

14 November 2007 at 9:56am Community Member, 787 Posts

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;
   }

Avatar
sonicparke

14 November 2007 at 12:26pm 74 Posts

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.

Avatar
Sam

14 November 2007 at 1:36pm Administrator, 679 Posts

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.

Avatar
sonicparke

14 November 2007 at 1:47pm (Last edited: 14 November 2007 1:49pm), 74 Posts

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

Avatar
Sam

14 November 2007 at 3:04pm (Last edited: 14 November 2007 3:05pm), Administrator, 679 Posts

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.

Avatar
sonicparke

14 November 2007 at 5:11pm 74 Posts

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!