I have a optional dateFinished attribute in my Record:
protected function defineAttributes()
{
return array(
...
'dateFinished' => AttributeType::DateTime,
...
);
}
Some Records have it set to a DateTime other have it set to null (default).
To prevent Twig errors I tried using the is defined test:
{{ log.dateFinished is defined ? log.dateFinished|date('m.d.y - H:m'|t) : '-'}}
But this doesn't work, I'm getting the typical "Scope error". After taking a look at the dump() it looks that even a null value is getting defined:
["dateFinished"]=>
object(Craft\DateTime)#2670 (3) {
["date"]=>
string(19) "2014-07-15 17:48:25"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
....
["dateFinished"]=>
array(2) {
["column"]=>
string(8) "datetime"
["type"]=>
string(8) "datetime"
}
I tried to solve this by "Check(ing) if a variable is a date with Twig":
{{ log.dateFinished is defined and log.dateFinished.timestamp is defined ? log.dateFinished|date('m.d.y - H:m'|t) : '-'}}
But this doesn't make a difference, I'm still getting the "Scope error". Any ideas?
log.dateFinished is defined and log.dateFinished is not iterable. – Victor Jul 15 '14 at 23:31Craft\Mailer_LogRecord and its behaviors do not have a method or closure named "dateFinished".– Victor Jul 15 '14 at 23:39model()needs to be added:Mailer_LogRecord::model()->populateRecord($log)– Victor Jul 16 '14 at 17:08