gantry5
gantry5 copied to clipboard
override for modules.php
I've finally implemented a way to use your own
custom/gantry/theme.yaml
file. I chose to go for a simple solution: if the file exists, it will be used instead of the default file. So if you override the file (or any other file), it is a good idea to check now and then if it has changed. Generally, themes have been very stable and most changes are between larger versions: 5.4 -> 5.5 -> 5.6...Please check if it now works for you in CI build: https://gantry.org/downloads#ci-builds
PS. make sure you pick the correct file for your CMS.
Originally posted by @mahagr in https://github.com/gantry/gantry5/issues/904#issuecomment-1127825324
@mahagr would you be able to do something similar for the /template/html/modules.php file?
Maybe put it in custom/html/modules.php
I am using an extension that, with some modifications to the file, allows me to prevent modules from loading. It's different from using the built-in Gantry classes because those just hide things whereas this extension, with the modifications to the file, prevent it from even being loaded unless it is allowed for the specific device being used to view it.
I'm asking for this because every time I update template the file gets overridden and I have to go back in and re-add the changes.
regards,
Michael
I was thinking of it already. Basically, it means that the file itself tries to load another file as the issue is that you cannot define the same class twice. Hmm... Maybe it is possible to put the class into an if and make it work in that way...?
Here is what I am using as the "addition" to the modules.php file.
Directly below this line
function modChrome_gantry($module, &$params, &$attribs)
you add the following:
$moduleParams = json_decode($module->params);
if($moduleParams->moduleclass_sfx === 'dsc-notmobile' && PlgSystemDeviceSpecificContent::isMobile()) { return; } if($moduleParams->moduleclass_sfx === 'dsc-mobile' && PlgSystemDeviceSpecificContent::isNotMobile()) { return; } if($moduleParams->moduleclass_sfx === 'dsc-nottablet' && PlgSystemDeviceSpecificContent::isTablet()) { return; } if($moduleParams->moduleclass_sfx === 'dsc-tablet' && PlgSystemDeviceSpecificContent::isNotTablet()) { return; } if($moduleParams->moduleclass_sfx === 'dsc-notdesktop' && PlgSystemDeviceSpecificContent::isDesktop()) { return; } if($moduleParams->moduleclass_sfx === 'dsc-desktop' && PlgSystemDeviceSpecificContent::isNotDesktop()) { return; }
I tried to mark the above as code but for some reason it wouldn't work.
The above works with the Device Specific Content (DSC) extension from Kubik-Rubik. https://kubik-rubik.de/dsc-device-specific-content
I've also attached the modified modules.php file that I am using now so you can check it out. Just change the extension to .php
as I had to change it to .txt
in order to upload it here.
modules.txt
Let me know if this helps you understand what it is I'm doing and how it works. Thanks for looking at this!
mentioning: @Kubik-Rubik