This technical guide is designed for advanced users who need to customize their document templates in Buk using conditional logic, loops, and transformation filters. Using these tools allows a single document to dynamically adapt to each employee's information.
Golden Rule:To use any simple variable, it must be enclosed in double curly braces:
-
{{ variable.nombre }}.
Control Structures and Special Functions
Control structures allow you to manage visibility, data repetition, and extraction of specific payroll amounts.
| Structure / Function | Description | Example | Expected result |
|---|---|---|---|
| if | Evaluates a condition and displays the content only if it is true. | {%if empleado.nombre == "Pedro"%} Hola Pedro {%endif%} |
"Hello Pedro" (if applicable). |
| for | Iterates over collections (bonuses, dependents, permissions, etc.). | {%for bono in empleado.bonos%} {{bono.nombre}} {%endfor%} |
List of bonus names. |
| monto | Gets the amount of an item by its code and voucher type. | {%monto("buk_salario", "finiquito")%} |
"$ 1,000,000" |
| nombre | Gets the name of an item configured by its code. | {%nombre("buk_salario")%} |
"Base Salary" |
Transformation Filters
Filters modify the display of variables using the symbol|.Important:There should be no spaces between the variable and the symbol.
Filters modify the display of variables using the symbol|.Important:There should be no spaces between the variable and the symbol.
| Filter | Description | Example | Expected result |
|---|---|---|---|
| palabras | Converts numbers or dates to written text. | {{sueldo | palabras}} |
"five hundred thousand" |
| imagen | Displays an image (URL). Parameters: width, height. | {{empresa.logo | imagen: "200", "200"}} |
[Rendered image] |
| formato_fecha | Defines the format (yyyy, mm, dd, hh, MM, ss). | {{fecha_ingreso | formato_fecha: "dd-mm-yyyy"}} |
"12-31-2023" |
| detalle_fecha | Extracts a part: "A" (year), "M" (month), "D" (day). | {{fecha_de_hoy | detalle_fecha: "M"}} |
"03" (if March) |
| fecha_en_palabras | Full date in words according to mask. | {{fecha_de_hoy | fecha_en_palabras: "%d de %B"}} |
"March 17" |
| formato_numero | Applies thousands separator (.) and decimals (,) with 2 digits. | {{1000000 | formato_numero}} |
"1.000.000,00" |
| monto_con_formato | Applies standard currency format. | {{empleado.sueldo | monto_con_formato}} |
"$ 1,200,000" |
| convertir_a_mayusculas | Transforms the text to uppercase letters. | {{empleado.apellido | convertir_a_mayusculas}} |
"PÉREZ" |
| remove_zero | Removes the ".0" from decimal numbers. | {{empleado.horas_semanales | remove_zero}} |
"45" |
Logical Operators
Used within{%if ... %}tags to make comparisons.
| Operator | Description | Example | Expected result |
|---|---|---|---|
| == | Equal to | {%if empleado.genero == "Masculino"%} |
True if gender is Male. |
| != | Not equal to | {%if empleado.cargo != "Gerente"%} |
True if the position is not Manager. |
| greater_than | Greater than | {%if empleado.sueldo greater_than 100000%} |
True if the salary exceeds 100,000. |
| less_than | Less than | {%if empleado.antiguedad less_than 1%} |
True if less than 1 year. |
| greater_or_equal_than | Greater than or equal to | {%if variables.monto greater_or_equal_than 50%} |
True if it is 50 or more. |
| less_or_equal_than | Less than or equal to | {%if variables.edad less_or_equal_than 18%} |
True if it is 18 or less. |
| and | Logical "AND" operator | {%if var1 == "A" and var2 == "B"%} |
True only if both conditions are met. |
| or | Logical "OR" operator | {%if var1 == "A" or var2 == "B"%} |
True if at least one condition is met. |
Final Considerations
-
Mandatory Closing:Every
{%if%}must close with{%endif%}and every{%for%}with{%endfor%}. -
Use of Images:For variables such as
{{empresa.logo}},{{empleado.foto}}or file-type attributes, it isstrictly necessaryto use the| imagen: "ancho", "alto"filter. -
Escaping:In this guide,
\|is used for display in tables, but on the Buk platform simply|is used.
Enriched Practical Examples
1. Salary Clause in Words (Legal)
"The employee will receive a monthly base salary of{{empleado.sueldo | monto_con_decimales_a_palabras}}."Result: ...sum of five hundred thousand pesos 00/100.
2. Family Dependents Table
Using loops to list dependents:{%for carga in empleado.cargas%}
- Name:
{{carga.nombre}}- RUT:{{carga.rut}}- Relationship:{{carga.relacion}}{%for%}
3. Conditional Signatories
If the document requires a second signatory only in certain cases:{%if firma.segundo_firmante.nombre != ""%}Signature 2:{{firma.segundo_firmante.nombre}} {%endif%}
4. Custom Attributes with Image
If you have a "Scanned Signature" attribute of file type:{{empleado.custom_empleado.firma_escaneada | imagen: "150", "80"}}
5. Dynamic End Date
"The contract will be valid for 3 months, ending on{{fecha_de_hoy | fecha_n_meses_al_futuro: "3" | formato_fecha: "dd/mm/yyyy"}}."
💡Still have questions?
If this article does not fully answer your question or you need support for a particular case, our team is available through our support channels.
Chat | Phone | Email
🎓Interested in getting certified in Buk?
We invite you to take a course of your interest at Buk Academy, where you will find guided content to deepen your use of the platform and strengthen your knowledge.
🤖 This article was translated using artificial intelligence. View original article.