【问题标题】:Including javascript variable in ExpressionEngine path tag在 ExpressionEngine 路径标记中包含 javascript 变量
【发布时间】:2012-03-16 17:52:18
【问题描述】:

我想做类似的事情

$('a.filter-link').click(function(e) {
            e.preventDefault();
            var that = $(this), 
                categoryId = that.data('id'),
                categoryName = that.data('catname');
            $('div.results').load("{path='ums/performances-results/<I WANT var categoryName here>'}", {category: categoryId, ajax: true});
        });

如何将变量放在那里?这是模板页面中的内联,所以我知道 {path='ums/performances-results'} 有效,但我需要它依赖于 last_segment 变量。我只想渲染一个特定的模板,这样我就不必在过滤结果集时刷新整个页面。谢谢。

【问题讨论】:

  • 我们能看到用户点击的链接是什么样的吗?另外,您将“this”重命名为“that”是否有原因?

标签: php jquery expressionengine


【解决方案1】:

您不能混合使用 EE 标记和 JavaScript。部分 EE 代码库试图识别 JavaScript 花括号和 EE 括号之间的区别。有时它会失败,所以我们必须通过单独构造 EE 位而不是与类似的 JS 括号混合来帮助它。

以下是否有效?

$('a.filter-link').click(function(e) {
            e.preventDefault();
            var that = $(this),
                categoryId = that.data('id'),
                categoryName = that.data('catname');
            var path = "{path='ums/performances-results/'}"+categoryName;
            $('div.results').load(path, {category: categoryId, ajax: true});
});

您是否也尝试过仅放置 /ums/performances-results/ 而不是在 EE 中使用路径调用?

【讨论】:

    【解决方案2】:

    我没测试过,试试看:

     $('a.filter-link').click(function(e) {
                    e.preventDefault();
                    var that = $(this),
                        categoryId = that.data('id'),
                        categoryName = that.data('catname');
                    $('div.results').load("{path='ums/performances-results/'}"+categoryName, {category: categoryId, ajax: true});
                });
    

    【讨论】:

    • 不,没用。我认为 categoryName 需要以某种方式在 } 内。
    • 可能你需要转义变量:$('a.filter-link').click(function(e) { e.preventDefault(); var that = $(this), categoryId = that.data('id'), categoryName = that.data('catname'); $('div.results').load("{path='ums/performances-results/'+\'categoryName\'}", {category: categoryId, ajax: true}); });
    猜你喜欢
    • 2019-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-16
    • 2013-07-13
    • 2011-05-19
    • 2015-04-22
    • 2023-03-29
    相关资源
    最近更新 更多