hi josh,
one solution is to use another selector or resource type for your
included script.
eg:
/page
page.jsp
content.jsp
and in page.jsp you do:
<sling:include forceSelector="content" />
this will select the content.jsp as script when including 'this'
resource. the draw back of this is, that you 'destroy' any selectors
from the request, i.e. you can't propagate them into your content.jsp
without some manual magic.
another solution is using another resource type. eg:
/page
page.jsp
/content
content.jsp
and in page.jsp you do:
<sling:include resourceType="page/content" />
you could even make this work 'relative' eg:
String rt = resource.getResourceType() + "/content";
<sling:include resourceType="<%= rt =>" />
regards, toby
ps: i wrote an extended include tag that allows direct execution of
other scripts without having an extra 'include'. this is somewhat
contradictory to the sling philosophy that tries to hide the
script-resolution-magic from the user by the paradigm that only
'resources' are included. imo, in some cases, you really know what you
do, and you want to execute/include a designated script.
On 9/17/08, Joshua Oransky <[EMAIL PROTECTED]> wrote:
> Hello,
>
> How can I statically include code from another script? That is,
> include it into execution in the context of the currentNode. Sling.include
> does not work for me, because it executes in the context of the included
> node. I have several instances where I need to reuse code in different
> visual layouts. It seems inefficient to write the same code over and over,
> and is a maintenance nightmare. I know there's the sling:superResourceType,
> but that doesn't really solve my issue, as I want to have reusable snippets.
>
> Thanks - Josh
>