Is it possible to use a php varible instead of null here "->setFormatter( Format::ifEmpty( null ) )"

Is it possible to use a php varible instead of null here "->setFormatter( Format::ifEmpty( null ) )"

cha59cha59 Posts: 66Questions: 16Answers: 0

Hi
What I want is to set a standard value when creating a new post in DataTables. I know that I could just write this value here:
->setFormatter( Format::ifEmpty( 1924 ) )
but I want the standard value to be editable in my page for standards or defaults. So I have a PHP varible called $faktor, that I want the setFormatter to take insted of null. Is that possible?
->setFormatter( Format::ifEmpty( $faktor) ) doesn't work.
Any ideas?
Best regards
Claus

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 1,517Questions: 50Answers: 201
    Answer ✓

    Yes, it is called a custom setFormatter. You can do anything with it ...

    Here is an example:

    Field::inst( 'contract.type' )
        ->setFormatter( function($val, $data, $opts) {
            if ($data['contract']['instrument']  >= 'Y') {
                return '';
            } else {
                return $val;
            }
        }),
    
  • cha59cha59 Posts: 66Questions: 16Answers: 0

    Thanks a lot, I'll give et try.

Sign In or Register to comment.