Fix for issue #834

Use the linking function element instead of the template element when setting the parent.

Fixes issue #834