Skip to main content
updated output example to include entry var, like it should've all along
Source Link
Josh Angell
  • 2.3k
  • 17
  • 23

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' => array(AttributeType::Number, 'min' => 2, 'default' => 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...

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' => array(AttributeType::Number, 'min' => 2, 'default' => 12)
  );
}

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

The value is {{ myField }} of {{ 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...

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' => array(AttributeType::Number, 'min' => 2, 'default' => 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...

changed tag
Link
Victor
  • 8.4k
  • 1
  • 36
  • 61
Source Link
Josh Angell
  • 2.3k
  • 17
  • 23

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' => array(AttributeType::Number, 'min' => 2, 'default' => 12)
  );
}

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

The value is {{ myField }} of {{ 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...