问题描述:
最近学习discuz中要做一个焦点图,添加一个模板,让其显示后台推送图片,其中模块模板中要用到如下的代码
<div class="wrap"> <div id="slide-holder"> <div id="slide-runner"> [loop] <a href="{url}"{target}><img id="slide-img-{currentorder}" src="{pic}" class="slide" alt="{title}" /></a> [/loop] <div id="slide-controls"> <p id="slide-client" class="text"><strong></strong><span></span></p> <p id="slide-desc" class="text"></p> <p id="slide-nav"></p> </div> </div> </div> <script type="text/javascript"> if(!window.slider) { var slider={}; } slider.data= [ [loop] { "id":"slide-img-{currentorder}", // 与slide-runner中的img标签id对应 "client":"{title}", "desc":"{summary}" //这里修改描述 }, [/loop] ]; </script> </div>
会出现如下错误提示:
解决方法:
解决思路:问题出在[loop]标签,一个模板中只能有一个[loop],如果还想要有其余的[loop],我们可以用[loop1],[loop2]...最多可以有9个[loop],所以将代码改为:
1 <div class="wrap"> 2 <div id="slide-holder"> 3 <div id="slide-runner"> 4 [loop] 5 <a href="{url}"{target}><img id="slide-img-{currentorder}" src="{pic}" class="slide" alt="{title}" /></a> 6 [/loop] 7 <div id="slide-controls"> 8 <p id="slide-client" class="text"><strong></strong><span></span></p> 9 <p id="slide-desc" class="text"></p> 10 <p id="slide-nav"></p> 11 </div> 12 </div> 13 </div> 14 <script type="text/javascript"> 15 if(!window.slider) { 16 var slider={}; 17 } 18 19 slider.data= [ 20 [loop1] 21 { 22 "id":"slide-img-{currentorder}", // 与slide-runner中的img标签id对应 23 "client":"{title}", 24 "desc":"{summary}" //这里修改描述 25 }, 26 [/loop1] 27 ]; 28 </script> 29 </div>
问题便可解决