The Old Man Posted October 23, 2020 Posted October 23, 2020 Hi, I have a custom theme setting that works and I want to use the Condition field to only display if a previous custom (select type) theme setting isn't set to one of its key values, but I can't seem to get the right syntax: <?php if ( theme.my_other_custom_setting == 'value' ) return FALSE; I've tried with double curly brackets too. Also an ELSE returning TRUE. Many thanks.
Runar Posted October 23, 2020 Posted October 23, 2020 You should always use curly brackets, even if it might be valid syntax to drop them. They improve readability and prevents syntax errors. There’s really no reason not to use them. With that being said, have you tried to print the value of the other theme setting to see what it returns?
The Old Man Posted October 23, 2020 Author Posted October 23, 2020 Thanks, that's a good idea, I'll try next time I'm on my localhost. The info underneath that Condition field says to insert raw PHP. I've tried using the double curly brackets shown in the help guidance docs. There are a lot of examples of theme conditions but no example of what to use in this box.
The Old Man Posted October 24, 2020 Author Posted October 24, 2020 This format with one set of curly double braces seems to work in the Conditional field: <?php {{if ( theme.my_other_custom_setting == 'value' ) return FALSE;}}
The Old Man Posted October 24, 2020 Author Posted October 24, 2020 I spoke too soon! I thought this would show the custom theme setting B to the Admin dependant on the setting of a preceding custom setting A but it doesn't work. The custom theme setting it applies to (B) seems to show no matter if it returns a true or false Boolean.
bfarber Posted October 26, 2020 Posted October 26, 2020 I see you have an opening <?php tag there...are you doing this in an actual PHP file somewhere, instead of in a template? Within templates you can use "theme.setting_key" as a shortcut, and this gets expanded to valid PHP code. If you are using this in an actual PHP file you will need to do this instead: if( \IPS\Theme::i()->settings['setting_key'] == 'value' ) Note that you need to have the framework available. If this were in a standalone file (again I see you have an opening PHP tag there), that would require loading the init.php file and getting an instance of the external dispatcher. <?php require 'init.php'; \IPS\Dispatcher\External::i(); The Old Man 1
The Old Man Posted October 26, 2020 Author Posted October 26, 2020 (edited) 13 minutes ago, bfarber said: I see you have an opening <?php tag there...are you doing this in an actual PHP file somewhere, instead of in a template? Thanks Brandon, I'm trying to use the Condition field here, it inserts an opening PHP tag for you and says its for raw PHP, I didn't use a closing PHP tag: At the bottom it says you can make it (this custom setting) condition. I tried so many variations yesterday for over 8 hrs, I actually dreamt about it overnight! Basically, I just want to this custom setting to be displayed in the theme settings form depending upon the previous setting which is a select box containing line-gradient and radial-gradient. This field (site_title_color_gradient_direction) has no relevance if the user chooses the radial-gradient option in the first gradient-type setting site_title_color_gradient_type in my styles.css file and I have got it working on the front end with this: #elSiteTitle { background-image: {theme="site_title_color_gradient_type"}( {{if theme.site_title_color_gradient_type === 'linear-gradient'}} {theme="site_title_color_gradient_direction"} {{endif}} {hextorgb="site_title_color_gradient_start" opacity="1"}, {hextorgb="site_title_color_gradient_finish" opacity="1"}); -webkit-text-fill-color: transparent; background-clip: text; -webkit-background-clip: text; font: 400 {theme="site_title_font_size"}px Creepster, Helvetica, sans-serif; color: #fff; transition: all 300ms ease; } So for now, because I can't get the Condition field working, I've just added a note to this custom theme setting that says its ignored for radial gradients. Hope this makes sense! PS. 16 minutes ago, bfarber said: if( \IPS\Theme::i()->settings['setting_key'] == 'value' ) Does this apply to custom theme settings as well as default? Thanks. Edited October 26, 2020 by The Old Man
bfarber Posted October 27, 2020 Posted October 27, 2020 I'm going to tag @Ehren to check what you're doing here. I don't work too much with themes or custom theme settings so he'll have more familiarity than I with this area. The Old Man 1
Solution Ehren Posted October 27, 2020 Solution Posted October 27, 2020 On 10/27/2020 at 12:26 AM, The Old Man said: Basically, I just want to this custom setting to be displayed in the theme settings form depending upon the previous setting which is a select box containing line-gradient and radial-gradient. I experimented with a feature like this with my themes. I only wanted a setting to be displayed if a previous setting was set to a certain value. What I later realised is that the conditional setting will only be displayed once the existing setting has actually been saved. There isn't any ajax functionality which would make the "Gradient direction" setting appear as soon as "Radial gradient" is selected, which actually results in a pretty poor experience for admins since they won't see the new setting until they've saved the existing page and reloaded it. In my own themes, I've simply added a description to situations like this which basically says "If Radial Gradient is selected above, this setting will control its direction." I feel like this may also be the best solution in your case. The Old Man 1
The Old Man Posted October 27, 2020 Author Posted October 27, 2020 Thanks @Ehren I really appreciate that insight also because I've been working on my first theme with custom theme settings and being unfamiliar is the enemy! I thought it was meI So I wonder what purpose it actually serves then as a conditional field? Re adding a descriptive label, I found it's difficult to keep the label short and so I wondered if there a way to add a description under the custom theme setting like you can when you do a form for say a plugin's settings? In a plug-in form, you would append _desc to your language key and your description appears neatly under the field. I tried this yesterday and got an error message whilst in theme builder mode, it didn't like the _desc appendage on my custom form field at all, which seems odd as supposedly it's a form helper.
Ehren Posted October 28, 2020 Posted October 28, 2020 The desc tag works for me. I actually use it in my own theme settings: <?php $lang = array( 'themesetting_focus_light_dark_enable' => 'Enable light/dark toggle?', 'themesetting_focus_light_dark_enable_desc' => 'A toggle icon will be added to your theme allowing your members to easily switch to an alternate color scheme.', ); The Old Man 1
The Old Man Posted October 28, 2020 Author Posted October 28, 2020 Good to know, thanks. I'll try that again.
Recommended Posts