Jump to:

3401 Posts in 979 Topics by 855 members

Template Questions

SilverStripe Forums » Template Questions » No UpperCase?

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

Page: 1
Go to End
Author Topic: 2890 Views
  • ImacSS
    Avatar
    Community Member
    35 Posts

    No UpperCase? Link to this post

    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!

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: No UpperCase? Link to this post

    If you don't mind doing this in CSS, you can use the text-transform directive.

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

  • ImacSS
    Avatar
    Community Member
    35 Posts

    Re: No UpperCase? Link to this post

    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 *

  • ImacSS
    Avatar
    Community Member
    35 Posts

    Re: No UpperCase? Link to this post

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

  • Webbower
    Avatar
    Community Member
    10 Posts

    Re: No UpperCase? Link to this post

    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.

  • ImacSS
    Avatar
    Community Member
    35 Posts

    Re: No UpperCase? Link to this post

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

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: No UpperCase? Link to this post

    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

  • ImacSS
    Avatar
    Community Member
    35 Posts

    Re: No UpperCase? Link to this post

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

    thanks again...

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