nick
I'm new here

Accessing the currently generated page from a script

I'm using $CMS_RENDER(script:"...")$ in a page template in order to execute a script during generation. How do I access the currently generated page within the script, e.g. during preview generation? I tried context.getPage(), context.getGenerationContext().getPage() and some other accessors, but the result always seems to be null.

0 Kudos
3 Replies
feddersen
Community Manager

You can define additional parameters for you CMS_RENDER tag. See documentation.

So you could do something like this:

$CMS_RENDER(script:"yourscript", currentpage:#global.page)$

See here for more documentation on the #global object.

You can retrieve the parameters from the context object.

0 Kudos

Thanks. That will do it. But just out of curiosity: I expected to find the page somewhere in the generation context without passing it as a parameter. What is the reason that it's not there?

0 Kudos
feddersen
Community Manager

If you're using your script within a template, you can also access the current page via the GenerationContext object. See here. So you could do a context.getGenerationContext(),getPage()

0 Kudos