When a node has no template assigned return null

When a node has no template assigned return null instead of "Object
reference not set to an instance of an object" exception