掲示板

Custom velocity variables for Theme use

7年前 に e boats によって更新されました。

Custom velocity variables for Theme use

New Member 投稿: 18 参加年月日: 16/05/13 最新の投稿
We currently have a Hook class configured as a "servlet.service.events.pre" in portal.properties that sets some custom Velocity variables that we need available in our Theme. However, this class is getting fired many times (for each js/css/html resource) due to the "servlet.service.events.pre" config. Ideally, we'd like to have these variables set once per Theme/page load.

Is there some other approach (other than "servlet.service.events.pre") to setting custom Velocity variables (needed by the Theme) that would only fire once per Theme/page load? We only want to set these variables once per Theme/page load so am wondering how I'd go about doing that.
thumbnail
7年前 に Olaf Kock によって更新されました。

RE: Custom velocity variables for Theme use

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
e boats:
Is there some other approach (other than "servlet.service.events.pre") to setting custom Velocity variables (needed by the Theme) that would only fire once per Theme/page load? We only want to set these variables once per Theme/page load.


You can initialize them in your theme's _diffs/templates/init_ext.vm file. Naturally this will be a bit harder as it's in Velocity itself - you probably don't want a lot of code in there - but you can also just store a single simple object from Java and access the more complex initialization functionality from your theme precisely in init_ext.vm, where it'll only be triggered for the page being loaded.
7年前 に e boats によって更新されました。

RE: Custom velocity variables for Theme use

New Member 投稿: 18 参加年月日: 16/05/13 最新の投稿
Thanks for the info. Not sure I follow exactly. To clarify, we have a Java class configured in "servlet.service.events.pre" that calls a backend API to get certain values that we pass to our Theme velocity templates (e.g. init_custom.vm, header.vm, and footer).

If we removed the "servlet.service.events.pre" config, then how would my class get called to fetch these values needed by the Theme. Is there some way I can hook my class into the Theme page load lifecycle so that my class gets called just before the templates are initialized on page load?

We don't have a _diffs folder in our custom Theme project - we just have /css, /images, and /templates folders. Ideally, I'd like to leave our .vm files just the way they are in /templates, but somehow only populate them with the needed velocity variable values once per page load.

Can you point me to any info on init_ext.vm? Can't seem to find anything. Thanks so much for your help!