Using twig function instead of onPageLoaded event, cleanup