Visibility conditions - Syntax change #1
Replies: 8 comments 1 reply
-
Yes - for the Frontend If feature, I'm leaning toward using special tag attributes, in a similar direction as:
Especially the latter, the use of
That makes sense. By the way, the link goes to
The approach sounds good, to let the user build conditional rules as a data structure, more or less directly. But maybe Map, List, and Key are too low-level. This topic is related to It feels like <Condition action=show>
<And>
<Rule key=text_1 value="example-1" />
<Rule key=text_2 value="example-2" compare=not_equal />
</And>
</Condition> |
Beta Was this translation helpful? Give feedback.
-
Could someone clarify what "dynamic control conditions" means in this context? Are you saying that in the controls tab, the It certainly would make the language easier to learn if there was a consolidated logic syntax that worked differently behind the scenes, but @eliot-akira has shared the "leaky abstraction" Wikipedia article with me enough times that I understand how this can paint us into a corner. 😄 This is pretty neat.
Most graphic logic-builder UIs use nested rule groups with the ability to select whether the group uses |
Beta Was this translation helpful? Give feedback.
-
|
I think what @nicolas-jaussaud meant by "dynamic control conditions" are conditions that change in the browser ("frontend If"), in contrast to normal <If control="text_1" value="text value"> It only works on the frontend, and reacts (show/hide its content) when the control is changed. It's kind of just pretending to be an About logic variables, the way it works currently is kind of primitive. When setting a logic variable, it simply renders its content and checks that there is no Speaking of logic-builder UIs, one of the original references for the visibility logic UI was Beaver's. (From: Beaver Themer: Conditional logic APIs) What's interesting is that instead of providing operators like AND and OR, they solve it with a fixed structure: each rule group consists of rules that are combined with AND; and rule groups are combined with OR. Roughly, it looks like: type Condition = {
action: 'show' // Maybe other actions in the future
ruleGroups: RuleGroup[] // Combined with OR
}
type RuleGroup = Rule[] // Combined with AND
type Rule = {
fieldType: string
fieldName: string
operator: 'equal' | 'not_equal' | ..
value?: string
}It's a flat structure with no nested conditions, which makes it easier to evaluate. I wonder though, if there might be certain conditions that this structure is not able to express. But I'm guessing that this provides enough flexibility for most practical purposes. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for your answers!
Oops, I will edit the link I meant to use this site (still not as accessible as a WP Playground site as it requires to log in, but at least it can be reached haha)
Yes sorry that wasn't clear, by "dynamic" I indeed meant evaluated on the front-end
I like this syntax too, it seems that we don't lose any features from fields and it's still very readable Maybe we could use <Condition>
<Rule key=text_1 value="example-1" />
<Rule key=text_2 value="example-2" compare=not_equal />
</Condition>
We kept the same kind of structure for the conditional logic panel we started in fields too (it's not used in blocks yet but there is an example of it here) |
Beta Was this translation helpful? Give feedback.
-
Thanks for the clarification. It makes sense that our frontend-If and standard/server If would work differently, have access to different data, and have different syntaxes. But then wouldn't it make sense for control visibility logic and the frontend-If logic to use the same syntax?
I've noticed that a lot of logic UIs enforce a hierarchy like that ( |
Beta Was this translation helpful? Give feedback.
-
|
I'll try to bring the discussion back to the original question. The idea about a OK, to think this through, I'll summarize my understanding so far. What we need is a way to define rules that are evaluated on the frontend, and a syntax to conditionally show/hide controls based on those rules. The current syntax looks like: <If control="text_1" value="text value">
<Control type="text_2" name="text_2" label="Text value"/>
</If>This only works in the Controls tab of the block template edit screen. The way There's a new and better way to do visibility conditions in the Fields module. The heart of it is the JavaScript function Ideally, it would be nice if we can use the same data structure for conditional rules on the frontend and server side, with compatible evaluators written in JavaScript and PHP. So, I'd suggest implementing something like a Possible syntax to express the same logic as the example above: <Logic name=example>
<Rule control=text_1 value="some value" />
</Logic>
<Control type="text_2" name="text_2" label="Text value" logic=example />This will show the second control if the first control has a specific value. Internally, I suppose it will work similarly as the current syntax, where the rules are added to the visibility conditions passed to the frontend JS, to evaluate and show/hide controls dynamically. |
Beta Was this translation helpful? Give feedback.
-
|
I've started planning for the @nicolas-jaussaud I'll work in the direction we've discussed so far, and when there's some kind of interface prepared, we can "meet in the middle" somehow - where you can import some functions to use in Tangible Blocks and/or Fields, to replace the current syntax for visibility conditions. Maybe I'll prepare the basics first, and we can work together to develop it further based on what's needed. |
Beta Was this translation helpful? Give feedback.
-
|
OK, just to make a note of this, the foundation of the Logic module is prepared. And now we can work on integrating it with the Fields module and the Blocks plugin. |
Beta Was this translation helpful? Give feedback.



Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi @BenTangible @eliot-akira @juliacanzani!
I'd like to re-open the discussion from last year regarding the visibility conditions in block controls and validate/discuss a potential syntax change before starting to work on it
The previous discussion took place in the comments of this pull request and it was about the following:
1. Similar syntax for 2 different things
Currently we have this syntax, which is a regular L&L condition that can be used inside a template and will be evaluated on the server side:
We also have this syntax that can only be used inside the control tab of a block, and that will be evaluated dynamically on the client side:
On the controls tab of a block, regular L&L
<If>conditions can be used which can be misleading as you can't mix them with dynamic control conditionsThe idea was that we switch to a completely different syntax for the second snippet, to make it clear that it's a different concept
2. Migrate current visibility system to the one from fields
The current visibility system in blocks is a little hacky currently, because it was initially implemented when we used the native controls of each builder (so there is a lot of builder specific logic implemented)
Now that we have our own controls from the fields module, we should probably switch to the visibility condition system we implemented there as it will reduce the amount of builder specific code (it will be more reliable and easier to maintain)
We should probably try to do this migration and the syntax change at the same time
3. General visibility condition system on the client side
We discussed the possibility to implement a more general front-end
<If>in the future, but my understanding is that it will be a completely different feature, both in the syntax used an in the implementation (which means I don't really have to take that into account in blocks right now)Is that the case?
If what I said above is OK, a syntax I suggested last year was something like that:
Ideally I would like to be able to just "translate" the configuration we have in tangible-fields from PHP to L&L:
But my attempts to do it results in something very wordy and I'm not sure it's usable:
If you guys have some idea of syntax we could use let me know!
Beta Was this translation helpful? Give feedback.
All reactions