2017-03-17 23 views
0

我最近考察了一些網站的源,看到下面的代碼有沒有<# #>標籤?而如果沒有它可能在這段代碼有什麼用

<script type="text/html" id="tmpl-playlist-settings"> 
    <h2>Playlist Settings</h2> 

    <# var emptyModel = _.isEmpty(data.model), 
     isVideo = 'video' === data.controller.get('library').props.get('type'); #> 

    <label class="setting"> 
     <input type="checkbox" data-setting="tracklist" <# if (emptyModel) { #> 
      checked="checked" 
     <# } #> /> 
     <# if (isVideo) { #> 
     <span>Show Video List</span> 
     <# } else { #> 
     <span>Show Tracklist</span> 
     <# } #> 
    </label> 

    <# if (! isVideo) { #> 
    <label class="setting"> 
     <input type="checkbox" data-setting="artists" <# if (emptyModel) { #> 
      checked="checked" 
     <# } #> /> 
     <span>Show Artist Name in Tracklist</span> 
    </label> 
    <# } #> 

    <label class="setting"> 
     <input type="checkbox" data-setting="images" <# if (emptyModel) { #> 
      checked="checked" 
     <# } #> /> 
     <span>Show Images</span> 
    </label> 
</script> 

我認出了代碼使用PHP的「呼應」的風格(把代碼HTML裏面一個有條件的IF語句),儘管代碼在<# #>之內。 我從來沒有見過這種方法。它有什麼用途?

回答

2

如果這是一個wordpress模板,則任意邏輯將進入胡蘿蔔散列模板標籤<#// logic#>。

更多信息可以在這裏https://lkwdwrd.com/wp-template-js-templates-wp/

這才發現可能不僅適用於WordPress的。

<# if (data.trueValue) { #> 
    <p> I am only output if <code>data.trueValue</code> is true. 
<# } #> 

但可以適用於其他模板語言,藏漢,其它的變化可能是:

<% ... %>{{...}}等,根據不同的模板引擎。

+0

非常有趣..謝謝你的回答。 –

+0

@ 7asobate-你應該接受答案,如果它解決了你的問題 – smarber

相關問題