Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Page with individual objects

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 777 Views
  • barryvanveen
    Avatar
    Community Member
    11 Posts

    Page with individual objects Link to this post

    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

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Page with individual objects Link to this post

    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

  • barryvanveen
    Avatar
    Community Member
    11 Posts

    Re: Page with individual objects Link to this post

    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?

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Page with individual objects Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Page with individual objects Link to this post

    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()".

  • barryvanveen
    Avatar
    Community Member
    11 Posts

    Re: Page with individual objects Link to this post

    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

    777 Views
Page: 1
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.