agarcia
I'm new here

Call script template from another script template

Jump to solution

I have a funciton in Beanshell that I use across multiple scripts templates.

When I have to make changes to that function I have to modify multiple files.

I call those templates using $CMS_RENDER(...)$

I'd like to know if there is the possibility that I could do:

$CMS_RENDER(script:"script_a")$

$CMS_RENDER(script:"script_b")$

And inside them I could call "script_common_function" (I ignore the syntax).

I haven't found anything about "importing" another script in a Beanshell script.

I think this kind of call structure could be useful to store common functions, consts & vars.

Thank you!

1 Solution

Accepted Solutions
felix_reinhold
Returning Responder

Hello Andres,

there might be ways e.g. by using the RenderingAgent but you should definitely put those common functions in a FirstSpirit Module - that's the cleaner and more common approach.

Best regards

Felix

View solution in original post

4 Replies
felix_reinhold
Returning Responder

Hello Andres,

there might be ways e.g. by using the RenderingAgent but you should definitely put those common functions in a FirstSpirit Module - that's the cleaner and more common approach.

Best regards

Felix

robin_kump
I'm new here

Hello Andres,

Take a look at:

//!Beanshell

import de.espirit.firstspirit.access.store.Store;

import de.espirit.firstspirit.access.store.Store.Type;

import de.espirit.firstspirit.access.project.TemplateSet;

String getScript(uid) {

    TemplateSet firstTemplateSet = context.getProject().getTemplateSets().get(0);

    return context.getUserService().getStore(Store.Type.TEMPLATESTORE, true, true).getScripts().getScriptByName(uid).getChannelSource(firstTemplateSet);

}

eval(getScript("<UID>"));

That's the way we load Scripts from the project and execute them within Server Tasks sometimes. Technically not very sophisticated, but it works and completely sufficient for small scripts.

Best regards

Robin

felix_reinhold
Returning Responder

@Andres

Just as a small advice if you're planning to use Robins solution:

Since you are talking about a Render-Script yoou should implement sth. like a lazy loading for the script source - otherwise you would obtain it again for each render-call. This could be easily implemented with a small CMS_SET block-statement within the projectsettings template.

best regards

Felix

0 Kudos
agarcia
I'm new here

After thinking about it, I would go for with Felixs solution because I have big scripts to be imported.

Although I think Robins solution can be very useful in certain cases.

Thank you all!

0 Kudos