[BUGFIX] Make sure templates are not on deleted page

A fatal error was noticed upon deleting a content element when
a template is located on a deleted or not existing page.

The change makes sure to return valid templates from 
existing pages.
Merge pull request #46 from fudriot/patch-1

[BUGFIX] Make sure templates are not on deleted page