When creating a fieldtype how do I provide methods to be used in the templates? I have created a fieldtype that saves a single integer to the database, it has some settings that defines the maximum value that integer can be:

protected function defineSettings()
{
  return array(
    'maxNumber' =&gt; array(AttributeType::Number, 'min' =&gt; 2, 'default' =&gt; 12)
  );
}


What I want to do when outputting my field in the templates is something like this:

The value is {{ entry.myField }} of {{ entry.myField.maxNumber }}


Anyone have any ideas? Do I need to create a data class like the options-based fields use or something? I'm just stabbing around in the dark here...
Like plugins, fieldtypes can have their own settings as you're aware but while you can grab your plugin settings from pretty much anywhere, fieldtypes are a little more contextual.

In any case, like @Bryan pointed out, your fieldtype needs to implement prepValue($value) and ideally return a model containing the value as defined in defineAttributes() and the maxNumber as a property.

This basically means that when Craft calls your fieldtype's prepValue($value) which it does when the value of your field is needed (editing/outputting) you can return a model with the value and maxNumber.



EDIT:

// MyFieldType.php
public function prepValue($value)
{
    $model = new MyFieldModel;

    $model-&gt;setAttribute('value', $value);
    $model-&gt;setMaxNumber($this-&gt;getSettings()-&gt;getAttribute('maxNumber'));

    return $model;
}


// MyFieldModel.php
// Explicit getter/setter for $maxNumber rather than defining it as an attribute
protected $maxNumber;

public function setMaxNumber($value)
{
    $this-&gt;maxNumber = $value;
}

public function getMaxNumber()
{
    return $this-&gt;maxNumber;
}

public function defineAttributes()
{
    return array(
        'value' =&gt; AttributeType::Number,
    );
}


// _entry.html or other template name
{{ entry.myFieldHandle.value }}
{{ entry.myFieldHandle.maxNumber }}


@selvinortiz