Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Take content from other pages

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2678 Views
  • grilldan
    Avatar
    Community Member
    135 Posts

    Take content from other pages Link to this post

    Is there a way to take content from other pages?
    (in Page.ss)
    $Page(Blog).Content

    or something like that?

    If there is a way to do that, is there a way to show only like the first 3 posts?
    $Page(Blog).Content(3)

    What I am trying to do, is be able to include content from multiple pages and show that content through Page.ss.

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Take content from other pages Link to this post

    You can try these:

    $ChildrenOf(url-segment).Content

    As for limiting post count inside the template, the only way im aware of is:

    $ChildrenOf(blog-url-segment).Iterator.Offset(0)
    $ChildrenOf(blog-url-segment).Iterator.Offset(1)
    $ChildrenOf(blog-url-segment).Iterator.Offset(2)

    or

    $ChildrenOf(blog-url-segment).Range(0, 3)

    but im not sure if the second one will work in a <% control %> block.

  • grilldan
    Avatar
    Community Member
    135 Posts

    Re: Take content from other pages Link to this post

    I can't get these to work like I was hoping to.

    When I use any of those, it just places a link.

    Example...
    $ChildrenOf(Blog).Content
    This will add links to the blog posts.
    (here is what the html looks like.)

    <ul id="Menu1">
    <li onclick="location.href = this.getElementsByTagName('a')[0].href"><a href="">SilverStripe blog module successfully installed</a></li>
    </ul>
    .Content

    Is the syntax different?

    **edit**

    <% control ChildrenOf(Blog) %>
    $Content
    <% end_control %>

    This works

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Take content from other pages Link to this post

    My first snippet was stuffed up a bit - i just realised it would have to be nested inside a control as well.

    As for the snippet you posted, are you trying to achieve something like:

    <ul id="Menu1">
       <% control ChildrenOf(blog) %>
          <li><a href="$Link">$Title</a> - $Content.FirstParagraph</li>
       </ul>
    <% end_control %>

  • grilldan
    Avatar
    Community Member
    135 Posts

    Re: Take content from other pages Link to this post

    That code snippit was what

    $ChildrenOf(Blog).Content

    output (no <% control %>) just that line by itself.

    This does work though
    <% control ChildrenOf(Blog) %>
    $Content
    <% end_control %>

    By the way, Thank you

    You punted me in the right direction.

    --------------

    I still need to figure out somehow to limit it.

    lets say, I only need the first 4 images from the gallery page.

    Here are some things Ive tried.

    ChildrenOf(gallery).Iterator.Offset(2)
    ChildrenOf(gallery).Range(0, 3)
    ChildrenOf(gallery)(2)
    ChildrenOf(gallery).(2)

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Take content from other pages Link to this post

    Hi again grilldan,

    I think the problem is that currently <% control Something.SomethingElse(x) %> isn't supported. However, you can always use something like:

    <% control ChildrenOf(blog) %>
       <% control Range(0,3) %>
          $Content
       <% end_control %>
    <% end_control %>

  • grilldan
    Avatar
    Community Member
    135 Posts

    Re: Take content from other pages Link to this post

    Awesome =D Thanks!

    2678 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.