public function append($tag, $value, $encode = true)
    {
        if ($value instanceof URL) {
            $value = $value->__toString();
        }
        // Temporary here until we finish testing
        if ($encode
            && $value != $this->app->encodeHtmlChars($value, ENT_NOQUOTES)
            && $this->app->getConfig('html_injection_debug', false)
        ) {
            throw $this->exception('Attempted to supply html string through append()')
                ->addMoreInfo('val', var_export($value, true))
                ->addMoreInfo('enc', var_export($this->app->encodeHtmlChars($value, ENT_NOQUOTES), true))
                //->addAction('ignore','Ignore tag'.$tag)
                ;
        }
        if ($encode) {
            $value = $this->app->encodeHtmlChars($value, ENT_NOQUOTES);
        }
        if ($this->isTopTag($tag)) {
            $this->template[] = $value;

            return $this;
        }
        if (!isset($this->tags[$tag]) || !is_array($this->tags[$tag])) {
            throw $this->exception("Cannot append to tag $tag")
                ->addMoreInfo('by', $this->owner);
        }
        foreach ($this->tags[$tag] as $key => $_) {
            if (!is_array($this->tags[$tag][$key])) {
                //throw new BaseException("Problem appending '".
                //      $this->app->encodeHtmlChars($value)."' to '$tag': key=$key");
                $this->tags[$tag][$key] = array($this->tags[$tag][$key]);
            }
            $this->tags[$tag][$key][] = $value;
        }

        return $this;
    }