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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Take content from other pages


Go to End


7 Posts   3443 Views

Avatar
grilldan

Community Member, 135 Posts

4 September 2008 at 5:58pm

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

Community Member, 244 Posts

4 September 2008 at 6:22pm

Edited: 04/09/2008 6:22pm

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

Community Member, 135 Posts

4 September 2008 at 6:30pm

Edited: 04/09/2008 6:34pm

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

Community Member, 244 Posts

4 September 2008 at 6:34pm

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

Community Member, 135 Posts

4 September 2008 at 6:36pm

Edited: 04/09/2008 6:53pm

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

Community Member, 244 Posts

4 September 2008 at 8:39pm

Edited: 04/09/2008 8:39pm

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

Community Member, 135 Posts

4 September 2008 at 10:39pm

Awesome =D Thanks!