Jump to:

3431 Posts in 1025 Topics by 864 members

Template Questions

SilverStripe Forums » Template Questions » More than two arguments from template

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

Page: 1
Go to End
Author Topic: 1601 Views
  • Nathan Cox
    Avatar
    Community Member
    99 Posts

    More than two arguments from template Link to this post

    Hi, I'm trying to call a method of Page_Controller from the template, but if I try to pass in more than two arguments then none of them show up at the other end.

    I've got this going on:

    Page.php:

    class Page_Controller extends ContentController {
       function ArgTest($one='default', $two='default', $three='default') {
          print_r(func_get_args());
       }
    }

    Page.ss:

    $ImageTest(new, new, new)

    and the output is:

    Array ( )

    It's not passing the arguments in at all, but if I only pass two in ($ImageTest(new, new)) it works fine:

    Array ( [0] => new [1] => new )

    Anybody have any ideas what's going on? Is this a limitation of the template engine?

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: More than two arguments from template Link to this post

    I believe that SSViewer (the class that interprets your templates) doesn't handle more than 2 parameters.

    Basically, SSViewer parses the template with Regular Expressions. At the current time, these are limited to expressions with 2 parameters or less.

    You could probably modify SSViewer.php to handle more parameters if you wanted, but it is unusual to need them. The expressions are kept deliberately simple so it is easy for non-coders (designers, etc) to use. If you start building complicated functions with lots of parameters, you start to loose the compartmentalization.

  • Nathan Cox
    Avatar
    Community Member
    99 Posts

    Re: More than two arguments from template Link to this post

    Fair enough I guess, looks like I need to re-think how this bit's going to work.

  • DsX
    Avatar
    Community Member
    178 Posts

    Re: More than two arguments from template Link to this post

    I have found an inconsistancy.

    If I have a method: getData(var1=1, var2=2){do something etc..}

    and I call it in a template as: getData(5,6)
    the method is called and var1 is set to 5 and var2 is set to 6.

    if I call the method without the get, as: Data(5,6)
    the method is called and var1 remains default of 1 and var2 remains default of 2.

    Hamish, maybe you can explain if this is the expected behavior?
    I was under the impression that the get and set prefixes could be removed with out any effect?

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: More than two arguments from template Link to this post

    DsX: I can confirm your inconsistency, had this same issue on a site I was working on. SSViewer is a part of the code that scares me though so I skipped over trying to find a long term solution.

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