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.

Archive

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

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

Take content from other pages


Reply

7 Posts   2718 Views

Avatar
grilldan

4 September 2008 at 5:58pm Community Member, 135 Posts

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.

Avatar
ajshort

4 September 2008 at 6:22pm (Last edited: 4 September 2008 6:22pm), Community Member, 244 Posts

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.

Avatar
grilldan

4 September 2008 at 6:30pm (Last edited: 4 September 2008 6:34pm), Community Member, 135 Posts

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

Avatar
ajshort

4 September 2008 at 6:34pm Community Member, 244 Posts

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 %>

Avatar
grilldan

4 September 2008 at 6:36pm (Last edited: 4 September 2008 6:53pm), Community Member, 135 Posts

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 :D

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)

Avatar
ajshort

4 September 2008 at 8:39pm (Last edited: 4 September 2008 8:39pm), Community Member, 244 Posts

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 %>

Avatar
grilldan

4 September 2008 at 10:39pm Community Member, 135 Posts

Awesome =D Thanks!