2016-04-09 6 views
0

JavaScriptを使用してスクリプトテンプレートをインポートしたいのですが、このコードは機能しません。ありがとうございました。smartyを使用してJavaScriptでテンプレートファイルをインポートする

JS:

var tpl = {include file="myscript.tpl"}; 
$('.plus').html(tpl); 

ERROR:あなたのJavascriptがliteral tag以内おそらく

Uncaught SyntaxError: Unexpected identifier in 

var tpl = {include file="myscript.tpl"}; 
+0

'tpl'は有効なjavascriptオブジェクトではありません。 'var tpl = {includeFile:" myscript.tpl "};' –

+0

今私はエラーはありませんがテンプレートファイルはインポートされていません。 – CHARLI

+0

いいえ、わかりません... JavaScriptライブラリではなく、[docs#template](http://www.smarty.net/docsv2/en/template.resources)を読んでください.tpl#templates.from.template.dir)? –

答えて

0

ので、あなたは何をする必要があるかです:

{literal} 
<script> 
.... 
var tpl = '{/literal}{include file="myscript.tpl"}{literal}'; /* it will be a string */ 
.... 
</script> 
{/literal} 

This topicはまた、あなたを助けるかもしれません。

関連する問題