2

Sparkビューエンジンを使用して、文字通りのドル記号を出力し、中かっこ、テキストを開き、中かっこを閉じようとしています。${Hello}変数名を評価しようとするのではなく、どうすればSparkを発行させることができHelloますか?私が思いつくことができる最高のものはですが${'$'}{Hello}、それは複雑すぎて読みにくいようです。

コンテキストとして、私はSparkをASP.NET MVCビューエンジンとして使用していますが、テンプレートエンジンとしても使用しているため、アプリケーションの(上級)ユーザーは単純なSparkビューをテキスト領域に入力して保存できます。電子メールなどをレンダリングします。

ありがとう!

4

1 に答える 1

5

Sparkコード式をエスケープする方法は2つあります。

  1. 単一アイテムのエスケープ
  2. ブロック全体のエスケープ

単一アイテムのエスケープ

これは、式の種類ごとに3つのエスケープ文字のいずれかを使用して実行できます。説明するのではなく、以下はスパークビューでこれを行う方法の例です。

<div>
    $${Encoded.Escaped.with.a.dollar < 0}
    \${Encoded.Escaped.with.a.backslash < 0}
    `${Encoded.Escaped.with.a.backtick < 0}
</div>
<div>
    !!{Unencoded.Escaped.with.a.dollar < 0}
    \!{Unencoded.Escaped.with.a.backslash < 0}
    `!{Unencoded.Escaped.with.a.backtick < 0}
</div>
<div>
    $$!{Encoded.Silent.Nulls.Escaped.with.a.dollar < 0}
    \$!{Encoded.Silent.Nulls.Escaped.with.a.backslash < 0}
    `$!{Encoded.Silent.Nulls.Escaped.with.a.backtick < 0}
</div>

結果は次のように逐語的に出力されます。

<div>
    ${Encoded.Escaped.with.a.dollar < 0}
    ${Encoded.Escaped.with.a.backslash < 0}
    ${Encoded.Escaped.with.a.backtick < 0}
</div>
<div>
    !{Unencoded.Escaped.with.a.dollar < 0}
    !{Unencoded.Escaped.with.a.backslash < 0}
    !{Unencoded.Escaped.with.a.backtick < 0}
</div>
<div>
    $!{Encoded.Silent.Nulls.Escaped.with.a.dollar < 0}
    $!{Encoded.Silent.Nulls.Escaped.with.a.backslash < 0}
    $!{Encoded.Silent.Nulls.Escaped.with.a.backtick < 0}
</div>

ブロック全体のエスケープ

新しい特殊タグを使用して、<ignore>次のようにブロック内にあるものを逐語的に出力できます。

<html>
  <head>
    <title>ignore test</title>
  </head>
  <body>
    <h1>ignore test</h1>
    <p>${System.DateTime.Now}</p>
    <ignore>
        <div>
            Regular text ${This.isnt.code < 0}
            <var dummy="This isn't a variable" />
        </div>
    </ignore>
  </body>
</html>

お役に立てば幸い、
ロブ

于 2012-08-14T09:10:24.920 に答える