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

print out a string


Reply

5 Posts   2119 Views

Avatar
spullen

13 July 2007 at 5:02am 14 Posts

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

13 July 2007 at 8:21am (Last edited: 13 July 2007 8:22am), Google Summer of Code Hacker, 222 Posts

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: [url=http://doc.silverstripe.com/doku.php?id=tutorial:4-site-search#showing_the_results] tutorial:4-site-search -> Showing the results[/url]

Have a great day,

Elijah Lofgren

Avatar
spullen

13 July 2007 at 8:52am 14 Posts

That did the trick.

Thanks.

Avatar
xmedeko

13 July 2007 at 9:50am Community Member, 94 Posts

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

and in the template

<% $printThis %>

?

Avatar
qhoxie

14 July 2007 at 9:05am (Last edited: 14 July 2007 9:05am), Google Summer of Code Hacker, 39 Posts

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