The Old Man Posted December 11, 2023 Posted December 11, 2023 Hi, According to this help guide and an existing setting in the AdminCP https://invisioncommunity.com/4guides/themes-and-customizations/advanced-theming/managing-theme-settings-r128/ <?php 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: <?php 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: <?php 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?!
Solution Stuart Silvester Posted December 11, 2023 Solution Posted December 11, 2023 You would want to use \IPS\Theme::i()->settings['my_theme_setting'] The Old Man 1
The Old Man Posted December 11, 2023 Author Posted December 11, 2023 Thanks Stuart, just found the same in one of my old topics!
The Old Man Posted December 11, 2023 Author Posted December 11, 2023 (edited) Hmm, I'm wondering why this doesn't return true if this setting is enabled? <?php 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 December 11, 2023 by The Old Man clarification
Adriano Faria Posted December 11, 2023 Posted December 11, 2023 <?php return \IPS\Theme::i()->settings['my_theme_setting_enabled_or_not']; Do not attribute the value.
The Old Man Posted December 11, 2023 Author Posted December 11, 2023 (edited) Thanks, Adriano! Still not working though. The toggle setting is still hidden. Edited December 11, 2023 by The Old Man
Adriano Faria Posted December 11, 2023 Posted December 11, 2023 If you want to see its content, you should use print or echo instead of return. Return will work on a method/function.
The Old Man Posted December 11, 2023 Author Posted December 11, 2023 (edited) Thanks, I was sort of following the example of the recapcha image color in custom tab. I tried dumping it and comes back as NULL Edited December 11, 2023 by The Old Man
The Old Man Posted December 12, 2023 Author Posted December 12, 2023 Hi, 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). 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!
Adriano Faria Posted December 12, 2023 Posted December 12, 2023 There are 2 errors there and I told you yesterday.
The Old Man Posted December 12, 2023 Author Posted December 12, 2023 (edited) 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. 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 December 12, 2023 by The Old Man Further testing!
Nathan Explosion Posted December 12, 2023 Posted December 12, 2023 You mean this... Editing Default — Mozilla Firefox 2023-12-12 17-13-34.mp4 The Old Man 1
Nathan Explosion Posted December 12, 2023 Posted December 12, 2023 (edited) How much is it worth? mwahahahahaaaa But seriously...this is the conditional for the second of the 2 settings in that video: <?php return (boolean) $this->settings['neapp_theme_setting_1']; Edited December 12, 2023 by Nathan Explosion The Old Man 1
The Old Man Posted December 12, 2023 Author Posted December 12, 2023 (edited) LOL! Think I need to get the value and not the key! I'm close, I used array_values and custom theme settings are not in that array! print_r(array_values(\IPS\Theme::i()->settings)); exit; Edited December 12, 2023 by The Old Man
Nathan Explosion Posted December 12, 2023 Posted December 12, 2023 Mate...why are you still trying that? Look at what I posted...
The Old Man Posted December 12, 2023 Author Posted December 12, 2023 (edited) LOL Thanks! Didn't see your updated post. Doesn't work for me though! I can however now see all my custom theme settings though: <?php print_r(array_values($this->settings)); exit; Edited December 12, 2023 by The Old Man
Nathan Explosion Posted December 12, 2023 Posted December 12, 2023 OK, as you can see in my video it's working fine for me. Attaching another video of the full thing being done. video.zip The Old Man 1
The Old Man Posted December 12, 2023 Author Posted December 12, 2023 Thanks mate, yes that's exactly what I have but it doesn't work for me, even though it has too!
The Old Man Posted December 12, 2023 Author Posted December 12, 2023 Okay, I tried re-entering theme dev mode and now it works when saving and reloading the page. Weird.
Nathan Explosion Posted December 12, 2023 Posted December 12, 2023 (edited) I thought so... In that video, you appear to be expecting the toggling of the field to be 'live' - but it doesn't work like that. Change the first field, scroll down, click Save and reload, check the second field. That's what I am doing in the videos. Edited December 12, 2023 by Nathan Explosion The Old Man 1
The Old Man Posted December 12, 2023 Author Posted December 12, 2023 (edited) Thanks, TBH I thought I reloaded it but must have missed that. I did expect it to show when toggled on (live). It is working now, thank you so much for confirming the right syntax. I wrote a plugin once, and I'm sure it worked live when toggling. Recording 2023-12-12 182501.zip Edited December 12, 2023 by The Old Man
Nathan Explosion Posted December 12, 2023 Posted December 12, 2023 2 minutes ago, The Old Man said: wrote a plugin once, and I'm sure it worked live when toggling. Oh, that works in plugins/applications where you have complete control over the code of the fields. You don't have that with themes as fast as I can see. The Old Man 1
The Old Man Posted December 12, 2023 Author Posted December 12, 2023 Aha, thanks for that. It would be nice if it updated via Ajax or something. Thought I was going insane so I just watched my first video again, and I did save and reload at the very end but it didn't make the setting visible. Perhaps some kind of caching issue. Yes, I'll claim that!
Recommended Posts