Hive language
  • 28 Nov 2022
  • 3 Minutes to read
  • Contributors
  • Dark
    Light

Hive language

  • Dark
    Light

Article Summary

Types

Each value in Hive is of a certain type, which determines what you can do with that value. It is a statically typed language, unlike JavaScript for example. In short, this means that the language is very strict about which expressions you can combine. For a subtraction like 100 - 50, only numbers may be used - if you try to replace an operand with a text, the system shows an error. The aim here is to avoid mistakes and to point out a problem to the user immediately so that it is not discovered during the live operation of the configurator. You get the following types within Hive: 

  • Number
  • Text
  • Logic
  • List
  • Map
Every of these types has their own article with use cases and detailed descriptions.

Comments

Comments allow you to write down helpful information directly in your rules. They have no effect whatsoever on the rule itself, but they can help you or others better understand what the rule is all about.

To write a comment, start with two slashes // and then write whatever you want. This kind of comment takes up the remainder of the line. To write a comment over multiple lines, start with /* and end with */ when you're done.

Formatted Text

Start and end your text with three instead of one quotation mark. So you don’t have to escape another quotation mark in the text or in the HTML-formating text.

To include a value of another component in the text, you use {=ComponentName}

Example:

 """This is the text for the record component: „{=#TextRecord.Name}“!"""

Shown result: Das ist der Name der RecordComponent:"RecTopTyp"!

If you just use single quotation marks, you have to escape them: 

"This is an example text with \"qutoation marks\""

Shown result: This is an example text with "quotation marks" 

As mentioned above you can directly write HTML in a text value. Therefore always use the version with three quotation marks to avoid escaping every quotation mark in attributes of HTML tags.

"""
<table class="test-table">
  <tr>
    <td>Test</td>
    <td>Table</td>
  </tr>
  <tr>
    <td>Test</td>
    <td>Table</td>
  </tr>
</table>
"""

If you want to use a opening curly brace in your text while using three quotation marks, you have to type two curly braces: 

"""This is a curly {{brace}"""

Shown result: This is a curly {brace}

Input and empty

Some components allow the use of a special variable in their Hive rules, the input. This primarily refers to user input. For example, if you connect a value component with a UI element such as a text box, the text that a user writes in this text box ends up in the input variable. This way we can check user input and process it further. Each input value is also saved automatically, so we don't have to worry about that.

The easiest (but not completely correct) way would be to simply write "input" into a Hive rule and the component will automatically accept any value entered via a connected UI element. But what if the user has not yet entered a value? In this case, input has the special value empty. This means that the rule has no value and cannot be processed further.

Except for certain exceptional situations, you should avoid having a rule return empty.

How do I avoid empty values? A simple tool against empty is the or operator. It checks if the left operand is empty and if it is, it returns the right operand as result. If we have a rule like input or 1, we still get any user input via input, but in case there is none yet, we get the value 1.

You can use the or operator as shown in these examples. Of course, the number 1 and the empty quotation marks can be exchanged for any other number or text as needed and the logic can be changed to true.
For numbers: Input or 1
For text: Input or ""
For logic: Input or false

The values on the right side of the or operator are the default values that are used if no other input exists. This is an important aspect because the Combeenation configurators always show a valid and ready-to-order configuration right from the start. This valid initial product is therefore specified by the defined default values.


Was this article helpful?