Jump to:

3393 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » Template Parameter Parsing Problem

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

Page: 1
Go to End
Author Topic: 1486 Views
  • Terminator4
    Avatar
    Community Member
    81 Posts

    Template Parameter Parsing Problem Link to this post

    Hey guys,

    If I try and put the following dynamic variable in my template I get an error:

    $Top.ResortGroupForm($ID)

    This is what the cached file is trying to do for this section and obviously the SSVIEWER is getting confused due to there being no differentiation with the ID and the ResortGroupForm objects

    SSVIEWER;
    $val .= $item->obj("Top")->XML_val("ResortGroupForm",array("
    SSVIEWER;
    $val .= $item->XML_val("ID",null,true) ;
    $val .= <<<SSVIEWER
    "),true) ;
    $val .= <<<SSVIEWER

    --------------------------------------------------------------------------------------------------

    However, if I try a static value there is no problem:

    $Top.ResortGroupForm(one)

    The cached template looks like the following:

    SSVIEWER;
    $val .= $item->obj("Top")->XML_val("ResortGroupForm",array("one"),true) ;
    $val .= <<<SSVIEWER

    If anyone has a solution please provide it to me as it would be greatly appreciated.

    Thanks

  • Terminator4
    Avatar
    Community Member
    81 Posts

    Re: Template Parameter Parsing Problem Link to this post

    I would presume that if the SSVIEWER for the argument was something like SSVIEWER_ARG then that would solve the issue

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Template Parameter Parsing Problem Link to this post

    Hi Terminator4,

    At present, the template system doesn't support variables inside of template method calls (see http://doc.silverstripe.org/doku.php?id=templates#template_syntax). So, you can't do '$Property($OtherProperty)'.

    As a workaround to this, you could add a method to your model that returns the equivalent of '$Property($OtherProperty)'. You could then call that new method from your template.

    Hope this helps,
    Ben

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