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

Thought Process Behind Not Allowing Quoted Parematers


Go to End


8 Posts   3830 Views

Avatar
Ben Gribaudo

Community Member, 181 Posts

27 February 2009 at 3:12am

Hello,

As I've been setting up a new site in SS, I've encountered a couple of situations where I wanted to pass a string containing a comma in a template method call. Example: I'd like to have used "F, Y" as a date format string. However, if I did $Date.format(F, Y), the "Y" would be treated as a second argument. Something like $Date.format("F, Y") is not supported.

Do you know why it was decided to not allow quoted strings containing commas as parameters in template method calls?

Thank you,
Ben

Avatar
Hamish

Community Member, 712 Posts

27 February 2009 at 9:13am

My understanding is this: the template engine is designed to be used by non-programmers - or at least, designers with html knowledge but limited/no php background.

The date formatting is a classic example that highlights the point: "F, Y" means nothing to anyone who hasn't used the function before. The simplified templating forces you (the programmer) to create a meaningful function in the page model, like "MonthYear". This is something that a designer can look at and understand.

Avatar
Sam

Administrator, 690 Posts

27 February 2009 at 9:25am

To be honest, we would probably accept a patch that allowed the quoting of parameters. What we mainly wanted to avoid is the use of complex expressions in templates.

Avatar
Ben Gribaudo

Community Member, 181 Posts

27 February 2009 at 11:45am

I've begun working on a patch to allow quoted parameters. As a precursor to this, some unit tests have been submitted which test the parsing of template method calls.

Avatar
Ben Gribaudo

Community Member, 181 Posts

7 March 2009 at 3:09am

FYI, a proof-of-concept draft patch and a request for comments on it may be found at http://groups.google.com/group/silverstripe-dev/browse_thread/thread/7842ab97f687cd1e#. I'm waiting for some confirmation that my approach is a good approach before continuing developing the patch.

Avatar
Ben Gribaudo

Community Member, 181 Posts

17 March 2009 at 2:04am

Edited: 17/03/2009 2:05am

Sam,

I posted to the dev list about this a couple of weeks ago but have of yet received no responses. Maybe this functionality isn't of interest. Do you still think it is profitable for me to continue building this patch?

Thank you,
Ben

Avatar
Ben Gribaudo

Community Member, 181 Posts

19 March 2009 at 8:21am

The above-mentioned patch is attached to ticket #3738. Testers are needed to try it out!

Avatar
Nivanka

Community Member, 400 Posts

10 November 2009 at 3:25am

i found a little simple hack for this and blogged.

http://nivanka.blogspot.com/2009/11/using-commas-in-your-silverstripe.html