How to Use Twig Helper Functions in uKnowva HRMS Templates?

  • Print

Introduction

In an HRMS system, generating dynamic and well-formatted documents is essential for maintaining professionalism, accuracy, and compliance. Whether you are creating offer letters, salary slips, invoices, or internal communications, the way data is presented plays a critical role in improving readability and user experience.

uKnowvaprovides powerful Twig helper functions that allow you to format numbers, dates, currency values, and even secure sensitive information directly within templates. These helper functions eliminate the need for manual formatting and ensure consistency across all HR documents. By using these functions effectively, HR teams can automate document generation while maintaining clarity and compliance.

In this article, you will learn how to use the available Twig helper functions in uKnowva HRMS templates with proper understanding and real-world usage.

Accessing Letter Templates to Use Twig Helper Functions

Before using Twig helper functions, it is important to know where you can find them within the system. In uKnowva HRMS, these functions are primarily used inside document and communication templates such as offer letters, salary slips, and other HR documents.

To access this section, go to the side navigation panel of your uKnowva HRMS instance and click on the HR menu. From the list of options, select the Letter Templates sub-menu. This will open a page displaying all the templates available in your system.

Here, you can either create a new template by clicking on the add button or edit an existing template by locating it in the list and clicking on the edit button.

Once you open the template editor, you can start using Twig helper functions directly within the content to format values, display dynamic data, and secure sensitive information as required

Step 1: Use number_to_words to Convert Numeric Values into Words

To begin, you can use the number_to_words function when you want to display numeric values in written format. This function requires the PHP Intl extension, as it uses the NumberFormatter internally. If this extension is not available in your system, the function will simply return the original number instead of converting it into words.

The syntax used for this function is [[number_to_words(number, options)]], where the number parameter is mandatory and represents the numeric value that needs to be converted.

The function automatically cleans any commas or symbols present in the input. Along with this, you can pass optional parameters such as currency, which allows you to add a prefix like "Rupees," suffix to append text like "Only," and uppercase to convert the final output into capital letters.

When used in practice, this function converts values like 50000 into "Fifty thousand," and when combined with options, it can generate outputs such as "Rupees Fifty thousand Only." It also supports decimal values and converts them into point format, making it highly useful for financial documents like salary slips, offer letters, and invoices.

Now, let's understand the parameters used in this function:

→ number — This is a required parameter that takes the numeric value you want to convert into words. It automatically removes commas or symbols and supports both whole numbers and decimal values.

Example: [[number_to_words(1000)]]

Output: One thousand

→ options.currency — This is an optional parameter used to add a prefix before the converted value. For example, you can use values like "Rupees," "USD," or "Euro" depending on your document requirement.

Example: [[number_to_words(50000, { 'currency': 'Rupees', 'suffix': 'Only' })]]

Output: Rupees Fifty thousand Only

→ options.suffix — This is an optional parameter that allows you to append text after the converted words. It is commonly used in financial documents with values like "Only."

Example: [[number_to_words(50000, { 'currency': 'Rupees', 'suffix': 'Only' })]]

Output: Rupees Fifty thousand Only

→ options.uppercase — This is an optional boolean parameter which, when set to true, converts the entire output into uppercase. This is especially useful for official or legal documents where formatting standards require capitalized text.

Example: [[number_to_words(50000, { 'currency': 'Rupees', 'suffix': 'Only', 'uppercase': true })]]

Output: RUPEES FIFTY THOUSAND ONLY

Step 2: Use format_date to Display Dates in Readable or Relative Format

Next, you can use the format_date function to display date values in a structured and user-friendly format. This function works with standard PHP date handling and requires PHP 5 or above, using strtotime() internally to process date values.

The syntax for this function is [[format_date(date, format)]], where the date parameter is required and accepts any valid date string, while the format parameter is optional. This format parameter allows you to define how the date should appear, such as "d-m-Y" for numeric format or "d F Y" for a more descriptive format.

In addition to standard formatting, the function also supports a relative mode. When you pass "relative" as the format, the system dynamically converts the date into expressions like "Just now," "2 hours ago," or "2 days ago," depending on the time difference. This makes it extremely useful for dashboards, notifications, and activity logs.

Now, let's understand each parameter in a simple and practical way:

date — This is the date value that you want to format. It is a required parameter and accepts any valid date string supported by strtotime(), such as Y-m-d, d-m-Y, or even timestamp strings.

Example: [[format_date(date_of_joining, 'd-m-Y')]]
Output: 25-02-2026

→ format — This parameter defines how the date should appear in the final output. By default, it uses the format 'd-m-Y', but you can customize it using any valid PHP date() format. You can also use "relative" to display time differences such as "2 days ago" or "just now," which is helpful for dashboards and notifications.

Example: [[format_date(date_of_joining, 'd F Y')]]
Output: 25 February 2026

Example (Relative Format): [[format_date(application_date, 'relative')]]
Output: 2 days ago

Step 3: Use number_format_custom for Better Number Readability

When handling large numbers, the number_format_custom function helps improve readability by adding comma separators. This function is based on PHP's built-in number_format functionality and works with PHP 5 and above.

The syntax for this function is [[number_format_custom(number, decimals)]], where the number parameter is required and represents the value to be formatted. The decimals parameter is optional and allows you to define how many decimal places should be displayed, with the default being zero.

For example, a number like 1500000 is displayed as "1,500,000," and if decimals are specified, it can appear as "1,500,000.50." This function is commonly used in payroll reports, CTC breakdowns, and financial summaries where clarity of large numbers is important.

Now, let's understand each parameter in a simple and practical way:

number — This is the numeric value that you want to format. It is a required parameter and ensures that large numbers are displayed with proper comma separation. If a non-numeric value is passed, the function will return it as it is without applying any formatting.

Example: [[number_format_custom(1200000)]]
Output: 1,200,000

decimals — This parameter allows you to control the number of decimal places in the output. It is optional, and if not provided, the default value is 0. This is useful when you want to display precise financial values.

Example: [[number_format_custom(1200000.5, 2)]]
Output: 1,200,000.50

Step 4: Use currency_format to Display Currency Values Professionally

To present numeric values in a proper currency format, you can use the currency_format function. This function requires the PHP Intl extension, as it uses NumberFormatter with currency support to ensure accurate formatting.

The syntax for this function is [[currency_format(number, options)]], where the number parameter is required. The options parameter is optional and allows you to define values such as currency code, locale, and decimal precision.

By default, the function formats numbers according to system settings, such as displaying 50000 as "₹50,000.00." However, you can customize this for international use cases, for example displaying the same value as "$50,000.00" by setting the currency to USD and locale to en_US.

This makes the function highly useful for global payroll systems, international offer letters, and financial reports.

Now, let's understand each parameter in a simple and practical way:

number — This is the numeric value that you want to convert into currency format. It is a required parameter and ensures that the value is displayed with proper currency formatting, including symbol and decimal places.

Example: [[currency_format(50000)]]
Output: ₹50,000.00

options.currency — This parameter allows you to define the currency code using standard ISO formats such as INR, USD, EUR, or GBP. It is optional and defaults to INR if not specified. This is useful when working with global payroll or international documents.

Example: [[currency_format(50000, { 'currency': 'USD' })]]
Output: $50,000.00

options.locale — This parameter controls how the currency is displayed based on regional formatting rules, such as symbol placement and number separators. It is optional and defaults to 'en_IN'.

Example: [[currency_format(50000, { 'currency': 'EUR', 'locale': 'de_DE' })]]
Output: 50.000,00 €

options.decimals — This parameter allows you to override the default decimal precision. It is optional and defaults to 2 decimal places. This is useful when you want to control rounding or display more precise values.

Example: [[currency_format(50000.567, { 'decimals': 3 })]]
Output: ₹50,000.567

Step 5: Use secure_mask to Protect Sensitive Information

To ensure data privacy and compliance, you can use the secure_mask function to hide or restrict sensitive information. This function works with standard PHP environments and also considers user context and permissions within the system.

The syntax for this function is [[secure_mask(value, position, mask_count, rules)]], where the value parameter is required and represents the data to be masked. The position parameter determines where the masking should be applied, such as at the beginning, middle, or end. The mask_count defines how many characters should be hidden.

Additionally, the rules parameter allows you to define access control logic, such as specifying which users or groups can view the full value and which should see masked data. You can also customize the mask character or even return a hashed version of the data for higher security.

In real-world scenarios, this function is used to mask Aadhaar numbers, PAN details, email addresses, and bank information, ensuring that sensitive data is protected while still being partially visible where required.

value — This is the original data that you want to mask or protect. It is a required parameter and can be any sensitive information such as ID numbers, email addresses, or account details.

Example: [[secure_mask('123456789012')]]
Output: XXXXXXXX9012

position — This parameter defines where the masking should be applied. You can choose to mask from the beginning (first), middle, or end (last). By default, it masks the last portion of the value.

Example: [[secure_mask('This email address is being protected from spambots. You need JavaScript enabled to view it.', 'middle', 5)]]
Output: john*****@example.com

mask_count — This parameter controls how many characters should be masked. It is optional and defaults to 4. You can increase or decrease this based on how much data you want to hide.

Example: [[secure_mask('9876543210', 'first', 6)]]
Output: XXXXXX3210

rules.owner_id — This parameter allows full visibility of the value to a specific user (usually the owner of the data). If the logged-in user matches this ID, masking will not be applied.

Example: [[secure_mask(AADHAAR_NUMBER, 'last', 4, { 'owner_id': employee_id })]]
Output: Full value visible to owner, masked for others

rules.include_groups — This parameter allows specific user groups to view the full value without masking. It is useful when certain roles like HR or Admin need complete access.

Example: [[secure_mask(PAN_NUMBER, 'last', 4, { 'include_groups': [1,2] })]]
Output: Full value visible for allowed groups

rules.exclude_groups — This parameter restricts specific user groups from viewing the full value, even if they might have access otherwise.

Example: [[secure_mask(PAN_NUMBER, 'last', 4, { 'exclude_groups': [3] })]]
Output: Masked value for excluded groups

rules.include_users — This parameter allows specific users (based on user IDs) to view the full value.

Example: [[secure_mask(BANK_ACCOUNT, 'middle', 6, { 'include_users': [101,102] })]]
Output: Full value visible for selected users

rules.exclude_users — This parameter explicitly denies certain users from seeing the full value, ensuring stricter control over sensitive data.

Example: [[secure_mask(BANK_ACCOUNT, 'middle', 6, { 'exclude_users': [105] })]]
Output: Masked value for excluded users

rules.mask_char — This parameter allows you to customize the masking character instead of the default "*".

Example: [[secure_mask('1234567890', 'middle', 4, { 'mask_char': '#' })]]
Output: 1234####90

rules.hash — This parameter converts the value into a secure SHA1 hash instead of masking it. This is useful when the original value should never be visible in any form.

Example: [[secure_mask('1234567890', 'last', 4, { 'hash': true })]]
Output: e807f1fcf82d132f9bb018ca6738a19f (sample hash)

Conclusion

That's it!

You've now successfully learned how to use Twig helper functions in uKnowva HRMS templates.

By following this process, you ensure that your templates are dynamic, well-formatted, and secure, with properly structured numbers, readable dates, formatted currency values, and protected sensitive information.

If you have any questions or need additional support, feel free to contact us at This email address is being protected from spambots. You need JavaScript enabled to view it..

Was this Article helpful?