public function getTagRef($tag, &$template)
    {
        if ($this->isTopTag($tag)) {
            $template = &$this->template;

            return $this;
        }

        @list($tag, $ref) = explode('#', $tag);
        if (!$ref) {
            $ref = 1;
        }
        if (!isset($this->tags[$tag])) {
            throw $this->exception('Tag not found in Template')
                ->addMoreInfo('tag', $tag)
                ->addMoreInfo('tags', implode(', ', array_keys($this->tags)))
                ;
        }
        $template = reset($this->tags[$tag]);

        return $this;
    }