0
votes

I have some components that I've broken into multiple smaller files. The main file includes them using data-sly-include attributes.

I'd like to generate HTML comments containing the current filename in both the main file and the included files, so that when I view the rendered output I can easily tell which file generated the output. Something like:

... 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 -->

I can see how to get the path to the current page, but that's the resource that contains my component; I want the paths to the files that make up the components. Any way to do this in Sightly?

1

1 Answers

0
votes

the sightly script engine has the current file as a binding variable with sling, so the following should work-

sling.getScript().getScriptResource().getPath()

you will have to put this in a js file and call it from all your sightly scripts.