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

print out a string


Go to End


5 Posts   2576 Views

Avatar
spullen

14 Posts

13 July 2007 at 5:02am

I have a controller that makes a string, then I return that string, how do I make the view render it.

This is what I have:

in the controller:
function printThis(){
$str = "Some string";
return $str;
}

In the .ss template:
<% control printThis %>
<p>$str</p>
<% end_control %>

What I have doesn't work, but is there any way to do this?

Avatar
elijahlofgren

Google Summer of Code Hacker, 222 Posts

13 July 2007 at 8:21am

Edited: 13/07/2007 8:22am

Hi spullen,

To make things work how you want, you'll need this in your controller:

	function printThis() {
		$data = array(
			'str' => "Some string"
		);
		return $this->customise($data);
	}

And and what you had in your .ss template will still work:
[html]
<% control printThis %>
<p>$str</p>
<% end_control %>
[/html]

For more information on this syntax see: tutorial:4-site-search -> Showing the results

Have a great day,

Elijah Lofgren

Avatar
spullen

14 Posts

13 July 2007 at 8:52am

That did the trick.

Thanks.

Avatar
xmedeko

Community Member, 94 Posts

13 July 2007 at 9:50am

Why not just
[code php]
function printThis(){
$str = "Some string";
return $str;
}

and in the template

<% $printThis %>

?

Avatar
qhoxie

Google Summer of Code Hacker, 39 Posts

14 July 2007 at 9:05am

Edited: 14/07/2007 9:05am

xmedeko, you are correct that this is a simpler way to go about it, but the template code would be this:

$printThis

without the <% and %>