0
私はいくつかのコンポーネントをいくつかの小さなファイルに分割しました。メインファイルには、data-sly-include
属性を使用したファイルが含まれています。Sightlyを使用して現在のファイルにサーバーパスを送信するにはどうすればよいですか?
メインファイルとインクルードファイルの両方に現在のファイル名を含むHTMLコメントを生成したいので、レンダリングされた出力を見ると出力を生成したファイルを簡単に知ることができます。次のようなものがあります。
... some HTML from the template or other components...
<!-- begin /path/to/main/file.html -->
<div>
This is from the main file
<!-- begin /path/to/main/includes/first.html -->
<p>This is fromt the first include</p>
<!-- end /path/to/main/includes/first.html -->
<!-- begin /path/to/main/includes/second.html -->
<p>This is fromt the second include</p>
<!-- end /path/to/main/includes/second.html -->
now we're back in the main file
<!-- end /path/to/main/file.html -->
現在のページへのパスを取得する方法はわかりますが、それは自分のコンポーネントが含まれているリソースです。私はコンポーネントを構成するファイルへのパスが必要です。視界でこれを行うには?
ありがとうございました!それはむしろ素朴な答えですが、それは私に十分な時間を与えました。私はそのコードを自分のコンポーネントとともに.jsファイルに入れます: 'use(function(){ return {" path ":sling.getScript()。getScriptResource()。getPath()}; 私のコンポーネントマークアップでは、 '<! - begin:$ {currentFile.path} - > 'とIレンダリングされたHTMLのコメント内のフラグメントへのパスが表示されるようになりました。警告:マークアップはJSスクリプトにアクセスする必要があります。同じディレクトリにない場合は、 '../'、 '/ etc/... 'などで適切に検索する必要があります。 –
Val