Hi,

If you want to load the functions from .../global/functions.esp into
content.esp, you would do

   load("/apps/admin/global/functions.esp");

in your content.esp ECMA script.

Alternatively, you may load the functions.esp once at the start of
request processing and have it available later. But his is currently not
possible due to a bug in the JavaScriptEngine, which creates a new scope
for each include instead of reusing any existing scope.

Regards
Felix

Joshua Oransky schrieb:
> I tried this, but all my functions in /apps/admin/global/functions.esp
> are not available in /apps/admin/main/content.esp even though my global
> is a sling:resourceSuperType of main, and I
> sling.include("admin/global.functions")... i try to call a function
> define in this esp on the content.esp, and it says undefined.
> 
> On Sep 26, 2008, at 2:25 AM, Felix Meschberger wrote:
> 
>> Hi Josh,
>>
>> What prevents you from using <@ page include /> ? This should work very
>> well.
>>
>> Please note that any script is run with a "current resource" in mind.
>> This "current resource" is available through the
>> SlingHttpServletRequest.getResource() method. Now, if you include a
>> script with
>>
>>   <sling:include resource="<%= currentResource %>"
>>            resourceType="something/else" />
>>
>> The script for something/else will be run with the "currentResource" as
>> its current resource, no matter where the script lies.
>>
>> Regards
>> Felix
>>
>> Joshua Oransky schrieb:
>>> This is an issue because I have several functions that I need to use all
>>> over, and the current resource include is insufficient. Right now, as I
>>> see it, I need to create redundant code in every script where I want to
>>> be able to use my functions... instead of just being able to include a
>>> script that has them all...
>>>
>>> Or am I mistaken? How can I create reusable code snippets?
>>>
>>> Thanks, Josh
>>>
>>> On Sep 17, 2008, at 12:59 PM, Tobias Bocanegra wrote:
>>>
>>>> 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
>>>>>
>>>
>>>
> 
> 

Reply via email to