protected function compile()
    {
        $objItemRenderer = new ItemList();

        $this->Template->searchable = !$this->metamodel_donotindex;

        $sorting   = $this->metamodel_sortby;
        $direction = $this->metamodel_sortby_direction;
        if ($this->metamodel_sort_override) {
            if (\Input::get('orderBy')) {
                $sorting = \Input::get('orderBy');
            }
            if (\Input::get('orderDir')) {
                $direction = \Input::get('orderDir');
            }
        }

        $objItemRenderer
            ->setServiceContainerFallback(
                function () {
                    return $this->getServiceContainer();
                }
            )
            ->setFactory(System::getContainer()->get('metamodels.factory'))
            ->setFilterFactory(System::getContainer()->get('metamodels.filter_setting_factory'))
            ->setRenderSettingFactory(System::getContainer()->get('metamodels.render_setting_factory'))
            ->setEventDispatcher(System::getContainer()->get('event_dispatcher'))
            ->setMetaModel($this->metamodel, $this->metamodel_rendersettings)
            ->setLimit($this->metamodel_use_limit, $this->metamodel_offset, $this->metamodel_limit)
            ->setPageBreak($this->perPage)
            ->setSorting($sorting, $direction)
            ->setFilterSettings($this->metamodel_filtering)
            ->setFilterParameters(
                StringUtil::deserialize($this->metamodel_filterparams, true),
                $this->getFilterParameters($objItemRenderer)
            )
            ->setMetaTags($this->metamodel_meta_title, $this->metamodel_meta_description);

        // Render items with encoded email strings as contao standard.
        $this->Template->items         =
            \StringUtil::encodeEmail($objItemRenderer->render($this->metamodel_noparsing, $this));
        $this->Template->numberOfItems = $objItemRenderer->getItems()->getCount();
        $this->Template->pagination    = $objItemRenderer->getPagination();
    }