Jump to:

3461 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » ShortCode Help

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

Page: 1
Go to End
Author Topic: 1126 Views
  • senica
    Community Member
    18 Posts

    ShortCode Help Link to this post

    Hi again....

    I added this to my page.php

    function NewsFeedSCH($arguments,$content = null,$parser = null) {
          // [NewsFeed id="Testimonials" num=2][/NewsFeed]
          if (!$arguments['id']) {
          $data = DataObject::get($arguments['id'], "", "", "", $arguments['num']); //Get Pages with ID Type
          $template = new SSViewer('NewsFeed');
          return $template->process(new ArrayData($data));   

    and the NewsFeed.ss file:

    <% control getSomething %>
       <div class="item">
          <div class="quote">“</div>
          <div class="blurb">$Content</div>
          <div class="title">$Title</div>
    <% end_control %>

    How do I register the $data variable so that I can loop through it in my template file since it is being called on the fly

    The news shortcode should look something like this: [NewsFeed id="Testimonials" num=2]

    I already have my shorcode parser in my _config.php file. I know that works.

    Thanks Again!

  • Pigeon
    Community Member
    243 Posts

    Re: ShortCode Help Link to this post

    try this:

    return $template->process(new ArrayData(array('Objects' => $data)));

    Then you can control 'Objects' in the template.

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.