參數

  • 內容:字串

    (選用)預設為空字串。

  • numChars:數字

    (選用)不顯示全文時顯示的字元數。 預設值為100。

  • moreText:字串

    (選用)要顯示的文字,表示還有更多文字要顯示。 預設值為「更多」。

  • 省略文字:字串

    (選用)要顯示的文字,表示有隱藏的文字。 預設值為「……」。

  • safeString:布林值

    (選用)布林值,指出在傳回結果之前是否要套用Handlebars.SafeString()。 預設值為false。

範例

{{content-loadmore  context numChars=32  moreText="go on"  ellipsesText="..." }}

/*
If context =
    "Here is the initial less content and this is more content."

Then content-loadmore would return
    "Here is the initial less content<span class="moreelipses">...</span> <span class="scf-morecontent"><span>and this is more content.</span>  <a href="" class="scf-morelink" evt="click=toggleContent">go on</a></span>"
*/

DateUtil

協助程式可傳回格式化的日期字串。

參數

  • 內容:數字

    (選用)從1970年1月1日起位移的毫秒值(紀元)。 預設值為目前日期。

  • 格式:字串

    (選用)要套用的日期格式。 預設值為"YYYY-MM-DDTHH:mm:ss.sssZ",結果顯示為"2015-03-18T18:17:13-07:00"

範例

{{dateUtil this.memberSince format="dd MMM yyyy, hh:mm"}}

// returns "18 Mar 2015, 18:17"
{{dateUtil this.birthday format="MM-DD-YYYY"}}

// returns "03-18-2015"

等於

根據等式條件傳回內容的協助程式。

參數

  • lvalue:字串

    要比較的左側值。

  • rvalue:字串

    要比較的右側值。

範例

{{#equals  value "some-value"}}
  <div>They are EQUAL!</div>
`{{else}}`
  <div>They are NOT equal!</div>
{{/equals}}

If-wcm-mode

區塊協助程式,可針對字串分隔的模式清單來測試WCM模式的目前值。

參數

  • 內容:字串

    (選用)要翻譯的字串。 若未提供預設值,則為必要。

  • 模式:字串

    (選擇性)要測試是否設定的WCM模式的逗號分隔清單。

範例

{{#if-wcm-mode mode="DESIGN, EDIT"}}
 ...
{else}}
 ...
`{{/if-wcm-mode}}`

i18n

此協助程式會覆寫Handlebars協助程式'i18n'。

另請參閱在JavaScript程式碼中國際化字串

參數

  • 內容:字串

    (選用)要翻譯的字串。 若未提供預設值,則為必要。

  • 預設:字串

    (選用)要翻譯的預設字串。 如果未提供內容,則為必要。

  • 註解:字串

    (選用)翻譯提示

範例

{{i18n "hello"}}
{{i18n "hello" comment="greeting" default="bonjour"}}

包含

將元件加入為範本中不存在資源的協助程式。

與新增為JCR節點的資源相比,此方法讓資源更容易以程式設計方式自訂。 請參閱新增或包含Communities元件

只有少數幾個社群元件可供包含。

此協助程式僅適用於伺服器端,可提供類似於JSP指令碼的cq:include的功能。

參數

  • 內容:字串或物件

    (選擇性,除非提供相對路徑)

    使用this傳遞目前內容。

    使用this.id取得位於id的資源,以呈現要求的resourceType。

  • resourceType:字串

    (選擇性)資源型別預設為來自前後關聯的資源型別。

  • 範本:字串

    元件指令碼的路徑。

  • 路徑:字串

    (必要)資源的路徑。 如果路徑是相對路徑,則必須提供上下文,否則會傳回空字串。

  • authoringDisabled:布林值

    (選用)預設為false。 僅供內部使用。

範例

{{include this.id path="comments" resourceType="social/commons/components/hbs/comments"}}

this.id + /comments中包含新的comments元件。

IncludeClientLib

包含AEM html使用者端程式庫的協助程式,可以是js、css或主題程式庫。 對於不同型別的多個包含專案(例如js和css),此標籤必須在Handlebars指令碼中多次使用。

此協助程式僅適用於伺服器端,提供類似於JSP指令碼的ui:includeClientLib的功能。

參數

  • 類別:字串

    (選用)以逗號分隔的使用者端程式庫類別清單。 納入指定類別的所有JavaScript和CSS資料庫。 主題名稱會從請求中擷取。

  • 佈景主題:字串

    (選用)以逗號分隔的使用者端程式庫類別清單。 包含指定類別的所有主題相關資料庫(CSS和JS)。 主題名稱會從請求中擷取。

  • js:字串

    (選用)以逗號分隔的使用者端程式庫類別清單。 包含指定類別的所有JavaScript程式庫。

  • css:字串

    (選用)以逗號分隔的使用者端程式庫類別清單。 包含指定類別的所有CSS資料庫。

範例

// all: js + theme (theme-js + css)
{{includeClientLib categories="cq.social.hbs.comments, cq.social.hbs.voting"}}

// returns
    <link href="/etc/clientlibs/social/hbs/tally/voting.css" rel="stylesheet" type="text/css">
    <link href="/etc/clientlibs/social/hbs/socialgraph.css" rel="stylesheet" type="text/css">
    <link href="/etc/clientlibs/social/hbs/comments.css" rel="stylesheet" type="text/css">
    <script src="/etc/clientlibs/social/hbs/tally/voting.js" type="text/javascript"></script>
    <script src="/etc/clientlibs/social/hbs/socialgraph.js" type="text/javascript"></script>
    <script src="/etc/clientlibs/social/hbs/comments.js" type="text/javascript"></script>

// only js libs
{{includeClientLib js="cq.social.hbs.comments, cq.social.hbs.voting"}}

// returns
    <script src="/etc/clientlibs/social/hbs/tally/voting.js" type="text/javascript"></script>
    <script src="/etc/clientlibs/social/hbs/socialgraph.js" type="text/javascript"></script>
    <script src="/etc/clientlibs/social/hbs/comments.js" type="text/javascript"></script>

// theme only (theme-js + css)
{{includeClientLib theme="cq.social.hbs.comments, cq.social.hbs.voting"}}

// returns
    <link href="/etc/clientlibs/social/hbs/tally/voting.css" rel="stylesheet" type="text/css">
    <link href="/etc/clientlibs/social/hbs/comments.css" rel="stylesheet" type="text/css">
    <script src="/etc/clientlibs/social/hbs/tally/voting.js" type="text/javascript"></script>
    <script src="/etc/clientlibs/social/hbs/comments.js" type="text/javascript"></script>

// css only
{{includeClientLib css="cq.social.hbs.comments, cq.social.hbs.voting"}}

// returns
    <link href="/etc/clientlibs/social/hbs/tally/voting.css" rel="stylesheet" type="text/css">
    <link href="/etc/clientlibs/social/hbs/socialgraph.css" rel="stylesheet" type="text/css">
    <link href="/etc/clientlibs/social/hbs/comments.css" rel="stylesheet" type="text/css">

美化時間

協助程式會顯示到達截止點之前經過的時間,之後會顯示一般日期格式。

例如:

  • 12小時前
  • 7天前

參數

  • 內容:數字

    與「現在」進行比較的過去時間。 時間以自1970年1月1日起位移的毫秒值表示(紀元)。

  • daysCutoff:數字

    切換到實際日期之前的天數。 預設值為60。

範例

{{pretty-time this.published daysCutoff=7}}

/*
Depending on how long in the past, may return

  "3 minutes ago"

  "3 hours ago"

  "3 days ago"
*/

Xss-html

協助程式會為HTML元素內容編碼來源字串,以協助抵禦XSS。

注意:此協助程式不是驗證器,且不可用於寫入屬性值。

參數

  • 內容:物件

    要編碼的HTML。

範例

<p>{{xss-html forum-ugc}}</p>

Xss-htmlAttr

協助程式會編碼來源字串,以寫入HTML屬性值,協助防範XSS。

注意:此協助程式不是驗證器,且不可用於撰寫可操作的屬性(href、src、事件處理常式)。

參數

  • 內容:物件

    要編碼的HTML。

範例

<div id={{xss-htmlAttr id}} />

Xss-jsString

協助程式會針對要寫入JavaScript字串內容的來源字串進行編碼,以協助防範XSS。

注意:此協助程式不是驗證器,且不可用來寫入任意JavaScript。

參數

  • 內容:物件

    要編碼的HTML。

範例

var input = {{xss-jsString topic-title}}

Xss-validHref

協助程式會清理要當作HTMLhref或srce屬性值寫入的URL,以協助防範XSS。

注意:此協助程式可能會傳回空字串。

參數

  • 內容:物件

    要清理的URL。