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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page with individual objects


Reply


6 Posts   862 Views

Avatar
barryvanveen

Community Member, 11 Posts

17 July 2010 at 9:27am

Hi all,

I know this has probably been asked a million times but I can't seem to find the answer. I have a NotulenPage type (www.mysite.com/notulen) which shows all Notulen-objects that I have attached to that page with the DOM module. When you click on an item you go to www.mysite.com/notulen/item/notulen-urlsegment. This should call the item-function in the NotulenPage controller. The output should be the data of that individual object. This doesn't work, the wrong template is used.

My code is like this:

class NotulenPage_Controller extends Page_Controller {

   function item() {

      //haal URLSegment van de notulen uit url
      $URLSegment = Convert::raw2sql(Director::urlParam("ID"));

      //haal notulen op met URLSegment
      $notulen = DataObject::get_one("Notulen", "URLSegment = '{$URLSegment}'");

      if ($notulen) {
      
         //zet the data in een array
         $data = array(
                  $this,
                  "Notulen" => $notulen
               );

         //voeg de data toe aan de template
         //render met template NotulenPage_item.ss NotulenPage.ss of Page.ss
         return $this->customise($data)->renderWith(array('Notulen_item','Notulen','Page'));

      } else {
      
         Director::redirect('/page-not-found');
         
      }
      
   }

}

Everything works (the function is called etc) but the wrong template is loaded. It should be /themes/myTheme/templates/Layout/NotulenPage_item.ss, but it is /themes/myTheme/templates/Layout/NotulenPage.ss

Can anyone tell what I'm doing wrong?

Cheers,

Barry

Avatar
Pigeon

Community Member, 243 Posts

17 July 2010 at 9:53am

Well, if all the code you have put there is the same code you are using, the problem is that your render with template array is referring to 'Notulen_item' where as your template name is NotulenPage_item.

Try swapping that.

Also, a little tip. For a better and more seamless 404 error:

return $this->httpError(404);

Rather than redirecting to the 404 page by URL

Avatar
barryvanveen

Community Member, 11 Posts

18 July 2010 at 2:34am

Thanks for the reply Pigeon, but I still can't get it to work. With the code in my first post I got a page rendered with the Page.ss template. Apparently this was the first template in the array it could find. Now I've tried a lot of different names for the other templates but they still don't show up.

My code is like this:

return $this->customise($data)->renderWith(array('NotulenPage_item', 'NotulenPage', 'Page'));

This way the page is rendered with the NotulenPage.ss template, which is almost good, I need it to be rendered with the NotulenPage_item.ss template. How do I accomplish this?

Avatar
Pigeon

Community Member, 243 Posts

18 July 2010 at 12:55pm

If the notulenpage_item template is in the same place as the notulenpage template then your code should work. Have you tried flushing?

Avatar
UncleCheese

Forum Moderator, 4094 Posts

18 July 2010 at 1:52pm

That doesn't look right to me. You've got too many templates in your renderWith function. You're way over thinking this. All you need is

return array(
"Notulen" => $notulen
);

The _item.ss template will automatically be rendered because the action is named "item()".

Avatar
barryvanveen

Community Member, 11 Posts

18 July 2010 at 10:37pm

Thanks UncleCheese!

Thought it had to be something like this, I've got it working now. There was another problem which caused a blank page. Instead of

<% control Notulen %>
...
<% end_control%>

I wrote

<% control $Notulen %>
...
<% end_control %>

This lead to a blank page without any error message. In my apache2/error.log the following error appeared "PHP Parse error: syntax error, unexpected '}' in /home/barry/public_html/catena/silverstripe-cache/.cache.home.barry.public_html.catena.themes.catenaBarry.templates.Layout.NotulenPage_item.ss on line 19
", which isn't very helpfull either.

Anyway, thanks for all the help, finally I can get on with the rest of the site :-)