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.

Template Questions

No UpperCase?


Reply

8 Posts   3157 Views

Avatar
ImacSS

27 March 2009 at 6:22am Community Member, 35 Posts

Creating a custom page type, and working on the custom template portion.

Have a need to convert the contents of a TextField to upper case.

Notice that $FieldName.LowerCase works just fine - but apparently $FieldName.UpperCase was left out?

Any ideas on how I can accomplish this?

Thanks!

Avatar
Ben Gribaudo

27 March 2009 at 9:12am Community Member, 181 Posts

If you don't mind doing this in CSS, you can use the [url=http://www.w3schools.com/css/pr_text_text-transform.asp]text-transform[/url] directive.

This may not be what you're looking for....

Avatar
ImacSS

28 March 2009 at 1:47am Community Member, 35 Posts

Appreciate the response Ben - but not quite what I was looking for.

Pretty astounded that they took the time to put in a LowerCase method, but decided to not take the extra step and supply a corresponding UpperCase method.

* scratches head *

Avatar
ImacSS

28 March 2009 at 2:45am (Last edited: 28 March 2009 2:45am), Community Member, 35 Posts

Well, regardless of why it wasn't added in - I decided to take some initiative and add the following code snippet to the file:
{SilverStripeDirectory}\sapphire\core\model\fieldtypes\DBField.php

function UpperCase() {
   return Convert::raw2xml(strtoupper($this->value));
}

I put this right underneath the LowerCase function.

Solved the problem...

Avatar
Webbower

31 March 2009 at 11:13am Community Member, 10 Posts

Has anyone figured out to add this kind of functionality to the DBField class and subclasses without hacking the core? I tried Object::useCustomClass() but apparently you can only use that for certain core classes. I've been wanting to add a toCamelCase and toSnakeCase method to Varchar and similar classes, but I haven't found out how to do it without hacking core files.

Avatar
ImacSS

1 April 2009 at 4:53am Community Member, 35 Posts

webbower - as I felt it bad form to update the core in order to add this functionality, I asked on the General Questions forum on the best way to get this functionality into the core for a future release.

http://silverstripe.org/general-questions/show/257202#post257202

As the method I'm proposing is ridiculously simple (just a copy of the toLowerCase except for UpperCase), I figure I'll just submit a simple patch request.

Hope that helps...

Avatar
Willr

1 April 2009 at 5:10pm Forum Moderator, 5511 Posts

ImacSS - functions in the core esp round strings, date etc are just added when we need them in a project. I doubt there is a 'design' decision behind not including it so I'm sure if you submit a patch it will be included in the next release :)

As for your post "How to make a recommendation?" I didnt see it in that forum but anyway as a note you should usually make a ticket on open.silverstripe.com with the patch / changes you wish. If its a large change or an API change then post it to the ss-dev mailing list as this will generate some discussion

Avatar
ImacSS

2 April 2009 at 2:57am Community Member, 35 Posts

willr - thank you very much for the info. I have posted a patch request using the info you provided.

thanks again...