Fix for issue #857

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