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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Extend NumericField with custom Template for model-admin


Go to End


752 Views

Avatar
Aurélien Chappard - Deefuse

Community Member, 5 Posts

27 September 2016 at 10:56pm

I try to extend the NumericField class to create my own fields in a model admin. Here is the code I use :

class EuroField extends NumericField
{

    public function __construct($name, $title = null, $value = '', $maxLength = null, $form = null) {
        parent::__construct($name, $title, $value);
        $this->setFieldHolderTemplate("EuroField_holder");
    }


    /**
     * {@inheritdoc}
     */
    public function Type() {
        return 'euro text';
    }
}

And now the template file : /themes/mytheme/templates/Includes/EuroField_holder.ss :
<div id="$HolderID" class="field<% if $extraClass %> $extraClass<% end_if %>">
    <% if $Title %><label class="left" for="$ID">$Title</label><% end_if %>
    <div class="middleColumn">
        $Field <span>THIS IS A TEST</span>
    </div>
    <% if $RightTitle %><label class="right" for="$ID">$RightTitle</label><% end_if %>
    <% if $Message %><span class="message $MessageType">$Message</span><% end_if %>
    <% if $Description %><span class="description">$Description</span><% end_if %>
</div>

Do you know why the template is not used?