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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Problem with displaying multiple content blocks


Reply


2 Posts   1248 Views

Avatar
MartinM

Community Member, 6 Posts

14 May 2009 at 1:57am

Edited: 14/05/2009 1:57am

Hi,

I love to use Silverstripe for small projects. This backend is so easy to use, that none of my customers had ever any problems using it. :)

But now I´m working on a bigger website with multiple content blocks. So I followed the [url=http://doc.silverstripe.org/doku.php?id=tutorial:2-extending-a-basic-site]Extending a basic site tutorial[/url], but something doesn´t work properly.

Since I want pages with content blocks, I made a new file under /mysite/code named BlockPage.php:

<?php

class BlockPage extends Page {
   
   static $db = array(
'2ndRowLeft' => 'HTMLText',
'2ndRowRight' => 'HTMLText'
);
   
   static $has_one = array(
   );
   
      /**
   * Additional Content Blocks
   */
   function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('2ndRowLeft'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('2ndRowRight'), 'Content');

return $fields;
}
   
}

class BlockPage_Controller extends Page_Controller {
   
}

?>

Of course I ran "/dev/build"

It works very good. I have two new editor fields, PhpMyAdmin shows the new tables and I can insert HTML into the DB (however, I don´t know how to put them AFTER "Content". Do I have to combine "addFieldToTab" with "insertAfter"? - But this is not the worst problem)

To display this two blocks on my BlockPage-type pages I made a copy of .../templates/Layout/Page.ss, called it BlockPage.ss and inserted $2ndRowLeft and $2ndRowRight:

<div class="typography">
   <% if Menu(2) %>
      <% include SideBar %>
      <div id="Content">
   <% end_if %>
         
   <% if Level(2) %>
       <% include BreadCrumbs %>
   <% end_if %>
   
      <h2>$Title</h2>
   
      $Content
      $Form
      <div class="2ndRowLeft">$2ndRowLeft</div>
      <div class="2ndRowRight">$2ndRowRight</div>
   
      
   <% if Menu(2) %>
      </div>
   <% end_if %>
</div>

But Silverstripe doesn´t display the HTML I inserted using my new editor fields. All I can see on the page are the variables "$2ndRowLeft" and "$2ndRowRight".

Did I miss anything?

/edit: Oh yes, I flushed it ;)

Avatar
MartinM

Community Member, 6 Posts

14 May 2009 at 4:30am

OK, I think I found it.

It seems that SS had a problem with my "$2ndRow..." variables. Changed everything to "$SecondRow..." and it works.