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.

Data Model Questions /

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

ShortCode Help


Go to End


2 Posts   1783 Views

Avatar
senica

Community Member, 18 Posts

20 June 2010 at 2:41pm

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']) {
			return;
		}
		
		$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>
	</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!

Avatar
dhensby

Community Member, 253 Posts

21 June 2010 at 10:37am

try this:

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

Then you can control 'Objects' in the template.