Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » <% control name_of function %>

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: 1077 Views
  • kusi
    Avatar
    Community Member
    21 Posts

    <% control name_of function %> Link to this post

    Hi,

    My problem is that I use php template and function there that returns for ex. "some text",
    and in .ss file when i use <% some_kind_edit_function %>$name_of_function<% end.. %>
    "some text" is always writed in the top of html page. Probably I could use html tags and css to position this, but some problems would stay. Has somebody had the same problem. knows how?I want It to be always in place where I wrote It in .ss file.....??

    bless

  • FlorianH
    Avatar
    Community Member
    33 Posts

    Re: <% control name_of function %> Link to this post

    Actually if you've got a function in your Controller which returns a string, you can use "$name_of_function" in the associated template without the "<% %>" tags. However, I'm never sure to write that function in the Controller or into the Page so you got to have some fun with try and error.

    And regarding to your Text positioned at the top of the page, I don't know if this is the case here, but this usually occcurs when having an echo in your Control-Function, so maybe you check out your PHP-code and your way to use that Control in your template.

    FlorianH

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: <% control name_of function %> Link to this post

    yes if you are returning a string from a PHP function echoAString() then make sure it returns rather then echos the string.

    FlorianH - all methods that you want to call from templates should be in the controller part of the class. As the Controller is the one that controls the templates. You can put methods in the Page part and call them from the Page_Controller if you need.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: <% control name_of function %> Link to this post

    Actually, I would recommend putting them in the model class. This is closer to the database and it's easier to manipulate data, while still being able to directly call those functions in the template.

    Adding lots of data related methods to the controller gives it too much responsibility for managing data. Also, you run into some issues like having to call $this->dataRecord to get the model record in order to get data from it, when the method could just go on the model instead. The template can still see all those methods on the model class thanks to a handy system called ModelAsController.

    This also means you can do this:

    $page = DataObject::get_one('Page');
    $page->MyMethod();

    If MyMethod was on the Page class, then it's callable in the above fashion. If it's on the Page_Controller class, you can't call it. This makes it easier to re-use code!

  • kusi
    Avatar
    Community Member
    21 Posts

    Re: <% control name_of function %> Link to this post

    My problem was echo function. Thanks a lot. But I return It in function readfile() imported from place that source is not accesible. I will rather use other function to get data, but most important to me was that echo is in the top.Right function was implode().
    .
    bless

    1077 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.