Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » can i execute function with variable in template ?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 2883 Views
  • snaip
    Community Member
    180 Posts

    Re: can i execute function with variable in template ? Link to this post

    new problem : )

    my funtion

       function showPDF($id) {
          $record = DataObject::get_by_id("File", $id);
          return $record;

    in template

    <% if PDFID %>
          <% control showPDF() %>
          <a href="$Filename"><img src="themes/tutorial/images/pdf_ikon.gif" width="32" height="32" /></a>
          <% end_control %>
    <% end_if %>

    and everything works great when i execute showPDF like this: <% control showPDF(204) %>
    but when i have: <% control showPDF($PDFID) %> i got an error:

    Parse error: syntax error, unexpected '}' in C:\Windows\Temp\silverstripe-cacheC--serwer-strony-ernesto\.cacheC..serwer.strony.ernesto.themes.tutorial.templates.Layout.EnPielgrzymkaPage.ss on line ....

    $PDFID is variable form database

  • Willr
    Forum Moderator
    5508 Posts

    Re: can i execute function with variable in template ? Link to this post

    As it says on the documentation page for templates - passing dynamic variables into functions is not supported yet.

    ok it works now but i cant use it in other <% control %>

    If you want to use the $replace_str on other page controllers other then the OkolicaMapaPage_Controller then it has to be in the model - OkolicaMapaPage class. Controllers aren't passed along when doing controls of other pages.

Page: 1 2
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.