Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » print out a string

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

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

Page: 1
Go to End
Author Topic: 2108 Views
  • spullen
    Avatar
    14 Posts

    print out a string Link to this post

    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?

  • elijahlofgren
    Avatar
    Google Summer of Code Hacker
    222 Posts

    Re: print out a string Link to this post

    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

  • spullen
    Avatar
    14 Posts

    Re: print out a string Link to this post

    That did the trick.

    Thanks.

  • xmedeko
    Avatar
    Community Member
    94 Posts

    Re: print out a string Link to this post

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

    and in the template

    <% $printThis %>

    ?

  • qhoxie
    Avatar
    Google Summer of Code Hacker
    39 Posts

    Re: print out a string Link to this post

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

    2108 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.