1

我有这个代码。

{if $loginUrl}
{literal}
<script type="text/javascript">
    var newwindow;
    var intId;
    function login() {
        var  screenX    = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft,
             screenY    = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop,
             outerWidth = typeof window.outerWidth != 'undefined' ? window.outerWidth : document.body.clientWidth,
             outerHeight = typeof window.outerHeight != 'undefined' ? window.outerHeight : (document.body.clientHeight - 22),
             width    = 500,
             height   = 270,
             left     = parseInt(screenX + ((outerWidth - width) / 2), 10),
             top      = parseInt(screenY + ((outerHeight - height) / 2.5), 10),
             features = (
                'width=' + width +
                ',height=' + height +
                ',left=' + left +
                ',top=' + top
              );

        newwindow=window.open('{$loginUrl}','Login by facebook',features);

        if (window.focus) {newwindow.focus()}
        return false;
    }
</script>
{/literal}
{/if}

它是 dwoo 模板,我想知道如何在 javascript 中使用我的 dwoo 变量?我试图在代码中看到它,但它不起作用。我需要在 {literal} 之间扭曲我的代码,以便它可以工作。

4

3 回答 3

4

删除 {literal} 标签。Dwoo 对此非常聪明,可以避免弄乱您的 javascript,除非您在一行中使用对象文字。

确切地说,{ 后跟任何空格、制表符或换行符都不会被 Dwoo 解析。唯一的问题是,如果您执行以下操作:

{foo: "bar"}

在这种情况下,您有几个选项可以阻止 Dwoo 解析:

\{foo: "bar"} // escape the {
{ foo: "bar"} // add a space so it doesn't match it
{literal}{foo: "bar"}{/literal} // wrap with literal, but then you can't use vars inside again

// or expand it to use multiple lines, which is usually more readable anyway
{
    foo: "bar"
}
于 2010-05-19T08:34:21.590 回答
-1

您可以{/literal}{$the_varible}{literal}在文字标签内插入变量。

于 2010-05-19T04:14:08.043 回答
-2

嗯..找到了一个“修复”,但它是硬编码的,应该有更好的东西:

    {if $loginUrl}
{literal}
<script type="text/javascript">
    var newwindow;
    var intId;
    function login() {
        var  screenX    = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft,
             screenY    = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop,
             outerWidth = typeof window.outerWidth != 'undefined' ? window.outerWidth : document.body.clientWidth,
             outerHeight = typeof window.outerHeight != 'undefined' ? window.outerHeight : (document.body.clientHeight - 22),
             width    = 500,
             height   = 270,
             left     = parseInt(screenX + ((outerWidth - width) / 2), 10),
             top      = parseInt(screenY + ((outerHeight - height) / 2.5), 10),
             features = (
                'width=' + width +
                ',height=' + height +
                ',left=' + left +
                ',top=' + top
              );

        newwindow=window.open({/literal}'{$loginUrl}'{literal},'Login by facebook',features);

        if (window.focus) {newwindow.focus()}
        return false;
    }
</script>
{/literal}
{/if}

只是……丑陋。

于 2010-05-19T04:20:57.733 回答