Jump to content

Use of theme setting in theme setting conditional logic field

Go to solution Solved by Stuart Silvester,

Recommended Posts


According to this help guide and an existing setting in the AdminCP



return \IPS\Settings::i()->bot_antispam_type === 'recaptcha2';

This would return true for use in a conditional theme setting so that a setting will be shown or not, but when I try this using my own custom theme setting:


return \IPS\Theme::i()->my_theme_setting == true;

it gives me an error:

Error: Undefined constant "my_theme_setting" (0)
#0 C:\laragon\htdocs\ips4-dev-theme3\system\Theme\Theme.php(1818): eval()
#1 C:\laragon\htdocs\ips4-dev-theme3\system\Theme\Theme.php(1797): IPS\_Theme->getCustomSettingField(Array)
#2 C:\laragon\htdocs\ips4-dev-theme3\system\Node\Controller.php(496): IPS\_Theme->form(Object(IPS\Helpers\Form))
#3 C:\laragon\htdocs\ips4-dev-theme3\system\Node\Controller.php(395): IPS\Node\_Controller->_addEditForm(Object(IPS\Theme))
#4 C:\laragon\htdocs\ips4-dev-theme3\system\Dispatcher\Controller.php(107): IPS\Node\_Controller->form()
#5 C:\laragon\htdocs\ips4-dev-theme3\system\Node\Controller.php(69): IPS\Dispatcher\_Controller->execute()
#6 C:\laragon\htdocs\ips4-dev-theme3\applications\core\modules\admin\customization\themes.php(59): IPS\Node\_Controller->execute()
#7 C:\laragon\htdocs\ips4-dev-theme3\system\Dispatcher\Dispatcher.php(153): IPS\core\modules\admin\customization\_themes->execute()
#8 C:\laragon\htdocs\ips4-dev-theme3\admin\index.php(13): IPS\_Dispatcher->run()
#9 {main}

I've also tried:


return theme.my_theme_setting == true;

This attempt produces no errors, but the theme setting doesn't show, it is hidden:

return $this->my_theme_setting == true;

and this one gives me undefined constant again!

return $this->theme.my_theme_setting == true;

Er, little help please?!

Link to comment
Share on other sites

Hmm, I'm wondering why this doesn't return true if this setting is enabled?

return \IPS\Theme::i()->settings['my_theme_setting_enabled_or_not'] == TRUE;

It relates to a custom theme setting (a toggle) that is enabled and directly precedes this one that I'm entering the conditional logic into?

Edited by The Old Man
Link to comment
Share on other sites


Do we know if this functionality is designed to work 'as is' in Custom Theme Settings?

Presumably, the setting is eval'd when the settings page loads or is updated via some AJAX or something so that it knows what to display.

It kind of seems back to front to me. Setting A should toggle Setting B on/off but the way it is set up says the code goes in Setting B (so it toggles itself on/off based on Setting A).

Could contain: Page, Text, File, Computer Hardware, Electronics, Hardware, Monitor, Screen

The text description below the Condition field suggests it should work, so it is probably a case of me not using the correct theme setting format, because although there is no error generated, all it seems to actually do is hide itself from view after saving. I can't see it working as the setting shows as NULL unless that's what it checks for. Maybe I should check for not null! 





Link to comment
Share on other sites

Thanks, I just took a screenshot while trying out different variations.

I did try your corrected syntax but for some reason, it didn't work.

Could contain: File, Page, Text, Computer Hardware, Electronics, Hardware, Monitor, Screen


Update: It returns NULL for other custom theme settings too. It works for a standard one like primary_button so I must have the syntax wrong for the variable. If it wasn't asking for raw PHP, I could just use theme.mysetting

Edited by The Old Man
Further testing!
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...