-1

我有下一个问题。我有这个代码来加载我的模板:

$.Mustache.load( "./templates/news/home.tpl" );

这是:

function load(url, onComplete)
{
    return $.ajax({
            url: url,
            dataType: options.externalTemplateDataType
    }).done(function (templates)
    {
        $(templates).filter('script').each(function (i, el)
        {
                add(el.id, $(el).html());
            });

            if ($.isFunction(onComplete)) {

                onComplete();
            }
    });
}

当我点击时,进入另一个页面:

$("body").append($.Mustache.render(pageId + "-template", data));

这是:

function render(templateName, templateData) {
    alert(!has(templateName));
    if (!has(templateName)) {

        if (options.warnOnMissingTemplates) {
            $.error('No template registered for: ' + templateName);
        }
        return '';
    }
    return getMustache().to_html(templateMap[templateName], templateData, templateMap);
}

所以我的问题在于: if (!has(templateName)) 因为该模板未加载,有什么问题?

4

2 回答 2

1

模板没有加载,因为我必须设置完整路径 - www/templates/news/home.tpl 有时会有延迟,WP 不会加载 *.tpl 格式的模板,所以我将其更改为 txt 并且一切正常

于 2013-08-02T06:37:18.000 回答
1

为什么不使用 *.html 扩展名?编辑器也会将其识别为 HTML 语法。:)

于 2015-03-16T12:46:20.173 回答