Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

More than two arguments from template


Go to End


5 Posts   2190 Views

Avatar
Nathan Cox

Community Member, 99 Posts

4 February 2009 at 4:33pm

Edited: 04/02/2009 4:33pm

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?

Avatar
Hamish

Community Member, 712 Posts

4 February 2009 at 5:08pm

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.

Avatar
Nathan Cox

Community Member, 99 Posts

4 February 2009 at 5:27pm

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

Avatar
DsX

Community Member, 178 Posts

23 November 2010 at 6:16am

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?

Avatar
Willr

Forum Moderator, 5523 Posts

23 November 2010 at 9:33pm

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.