Since the $sys.item.hasProperty() method will return false if the value of the property is null, then we need to use another method to determine if a property exists within the current item’s context.
Here’s a way that can be used in both a template and a binding:
$sys.item.getDefinition().getDefaultPrimaryType().getAllJSR170Properties().contains('rx:[i]property_name[/i]')
The “rx:” prefix is important here as the names in the returned property name set all have it, so without the prefix, you will always get false.
For example:
$sys.item.getDefinition().getDefaultPrimaryType().getAllJSR170Properties().contains('rx:sys_contentid')
will always return true.
Anotyher example:
$sys.item.getDefinition().getDefaultPrimaryType().getAllJSR170Properties().contains('rx:foo')
will return true only if the content type of the current item has a property defined called “foo”, otherwise, it’ll return false.