Foren
How to apply a hook only to a specific site?
Diogo Salazar, geändert vor 9 Jahren.
How to apply a hook only to a specific site?
Junior Member Beiträge: 51 Beitrittsdatum: 28.08.13 Neueste Beiträge
Hi to all,
I have a hook that modifies the Journal Article editor a little bit; now I want to deploy it to my portal but have it apply only to 1 of the many sites we have.
Is there an OOTB way to restrict a hook to a specific site?
Thanks
I have a hook that modifies the Journal Article editor a little bit; now I want to deploy it to my portal but have it apply only to 1 of the many sites we have.
Is there an OOTB way to restrict a hook to a specific site?
Thanks
Jeffrey Paul Handa, geändert vor 9 Jahren.
RE: How to apply a hook only to a specific site?
Liferay Master Beiträge: 541 Beitrittsdatum: 01.12.08 Neueste Beiträge
Hi Diogo,
Take a look at Application Adapters feature of JSP Hooks: https://dev.liferay.com/develop/tutorials/-/knowledge_base/6-2/customizing-sites-and-site-templates-with-application-adapters
Take a look at Application Adapters feature of JSP Hooks: https://dev.liferay.com/develop/tutorials/-/knowledge_base/6-2/customizing-sites-and-site-templates-with-application-adapters
Diogo Salazar, geändert vor 9 Jahren.
RE: How to apply a hook only to a specific site?
Junior Member Beiträge: 51 Beitrittsdatum: 28.08.13 Neueste Beiträge
Hi Jeffrey, thanks for the quick reply!
The content you've referenced is really spot on! That allowed me to apply a hook to a specific site.
My hook also contains modifications to JS and CSS files, those modifications did not apply; I've found a related thread (link) talking about the effects on CSS and JS files when setting <custom-jsp-global> to false in a hook plugin.
I've got two follow-up questions now:
Thanks in advance.
The content you've referenced is really spot on! That allowed me to apply a hook to a specific site.
My hook also contains modifications to JS and CSS files, those modifications did not apply; I've found a related thread (link) talking about the effects on CSS and JS files when setting <custom-jsp-global> to false in a hook plugin.
I've got two follow-up questions now:
- Is there an OOTB way to apply a hook only to a specific site that also applies CSS and JS modifications?
- I have a set of different hooks that I wanted to selectively apply to different sites, is there a way to apply more than one hook to a given website? (If not, is it in the roadmap?)
Thanks in advance.
Jeffrey Paul Handa, geändert vor 9 Jahren.
RE: How to apply a hook only to a specific site?
Liferay Master Beiträge: 541 Beitrittsdatum: 01.12.08 Neueste Beiträge
Hi Diogo,
1. What about providing JS and CSS through the theme? Each site could have a unique Color Scheme or Theme if you wanted each site to be different?
2. I don't believe there's a easy way to do that right now and I'm not sure if it's on the roadmap. Check out the Community Ideas page (https://www.liferay.com/community/ideas) to see if it's already been suggested. If not, go ahead and add it.
1. What about providing JS and CSS through the theme? Each site could have a unique Color Scheme or Theme if you wanted each site to be different?
2. I don't believe there's a easy way to do that right now and I'm not sure if it's on the roadmap. Check out the Community Ideas page (https://www.liferay.com/community/ideas) to see if it's already been suggested. If not, go ahead and add it.
Diogo Salazar, geändert vor 9 Jahren.
RE: How to apply a hook only to a specific site?
Junior Member Beiträge: 51 Beitrittsdatum: 28.08.13 Neueste Beiträge
Hi Jeffrey,
Thanks for looking into it.
I am modifying some functionality in the Control Panel that uses JS to render interactivity, so a theme won't cut it.
I actually ended up resorting to an alternative way of doing it:
So for example you could add a check at the beginning of the JSP file you're working on:
and then use it to apply the changes selectively:
Of course this was a quick-and-dirty method to accomplish it, so I might add it to the Ideas page.
Thanks again!
Thanks for looking into it.
Jeffrey Paul Handa:
1. What about providing JS and CSS through the theme? Each site could have a unique Color Scheme or Theme if you wanted each site to be different?
I am modifying some functionality in the Control Panel that uses JS to render interactivity, so a theme won't cut it.
Jeffrey Paul Handa:
2. I don't believe there's a easy way to do that right now and I'm not sure if it's on the roadmap. Check out the Community Ideas page (https://www.liferay.com/community/ideas) to see if it's already been suggested. If not, go ahead and add it.
I actually ended up resorting to an alternative way of doing it:
- Create a 'Custom Field' for pages that will allow you to toggle the hook on/off (boolean);
- Add directives in your hook to read that 'Custom Field' and selectively apply the modifications;
So for example you could add a check at the beginning of the JSP file you're working on:
Boolean _hookAllowsChanges = false;
try {
_hookAllowsChanges = ((ThemeDisplay)themeDisplay).getSiteGroup().getExpandoBridge().getAttribute(<your-custom-field-key>).toString().equals("true");
} catch (Exception e) { e.printStackTrace(); }</your-custom-field-key>
and then use it to apply the changes selectively:
<%
if(_hookAllowsChanges){
// MODIFIED CODE
} else {
// ORIGINAL CODE
}
%>
Of course this was a quick-and-dirty method to accomplish it, so I might add it to the Ideas page.
Thanks again!
sandeep jangam, geändert vor 7 Jahren.
RE: How to apply a hook only to a specific site?
New Member Beiträge: 12 Beitrittsdatum: 07.09.16 Neueste Beiträge
Yeah!
This works, We can apply hook to a specific site.
Sandeep.
This works, We can apply hook to a specific site.
Sandeep.