Change the title of the computed webform element conditionally - twig

I have a computed twig field in my webform that will calculate the total amount of money. Once it calculates the balance, I added an if statement that will change the title of the element (computed twig type) conditionally if the number calculated is smaller or equal to 0 from Total Reimbursement to Total Due Accounting then prints the absolute value of the number to avoid printing out a negative number. here is the if statement part in Computed value/markup I am having issue with (I will just attach the if statement part since I made sure the number is calculated correctly)
{% set reimbursement = (total_cost - total_amount)|round(2, 'ceil') %} {# calculating the total amount #}
{% if reimbursement <= 0 %}
{% [webform:element:total_reimbursement_01_total_reimbursement_:title] == 'Total Due Accounting' %} {# Here is where I am getting error at. I am trying to change the name of the title if the total amount is 0 or a negative number #}
{% set reimbursement = (total_amount - total_cost)|round(2, 'ceil') %}
{{'$ ' ~ reimbursement|number_format(2,'.',',') }}
{% else %}
{{'$ ' ~ reimbursement|number_format(2,'.',',') }}
{% endif %}
When I tried to save it in UI,I get an error that says Computed value/markup is not valid.
A block must start with a tag name in
"__string_template__7ee19d3ea967979a05c98764486ed96b961799aed3702bb3b9b515fd794f4099"
at line 23.
line 23 is the line where I tried to use the element's title. I believe this is how I pull the element's title, but seems like it's not.
Any help?

Related

How do you show content on certain day

Im trying to show a different page on certain days.
But I can't really figure it out in twig.
{% if "now" | date("l") %}
{% if "Sunday" %}
Sunday content
{% elseif "Tuesday" %}
Tuesday content
{% elseif "Wednesday" %}
Wednesday
{% else %}
default
{% endif %}
{% endif %}
This ofcourse isnt working.
Is there any way to do this with Twig?
Nevermind, found the issue.
The code should be:
{% if "now" | date('l') == 'Wednesday' %}

How change date in footer, insert only year

Opencart 3x How change date in footer, insert only years (html or javascript), no text ! (language/en-en/common/footer.php - $_['text_powered'] )
The real plece where the date implements in OpenCart 3 footer is in
catalog/controller/common/footer.php
$data['powered'] = sprintf($this->language->get('text_powered'), $this->config->get('config_name'), date('Y', time()));
This one is date
date('Y', time())
You can change 'Y' as you want using PHP date formats.
Also you can put current date directly to your footer.twig.
{{ "now"|date('d-m-Y H:i') }}

Netsuite / Freemarker - splitting item description by line is not working

Anyone who can help why the below code is not working.
This is my code:
<#list item.description?split("\n", 'r') as desc>
<tr>
<td align="left" colspan="23">${desc}</td>
</tr>
</#list>
I am editing an advance PDF/HTML template in Netsuite. I need to split the item description as 1 line per row. I wanted to split them like this because we have a case like for 1 item, there is a super long description and what happens is, instead of printing the items 1,2,3 in continuous flow, the print only displays 1 item in page 1 and the next item is in page 2 even though item 1 only occupied 10% of page 1. for item 2 (with very long description, it did occupy 100% of page 2).
If the code above is working correctly, then item 1 and item 2 should be printed on page 1 and some of the descriptions of item 2 should be on page 2.
I tried changing the code to <#list item.description?split(".") as desc> and it worked.
I found what works. Instead of "\n" or "\n", I use the br tag to split the item.descripiton.
<#list description?split("<br /><br />") as desc>

Get the number left to to match the Multiplication of 6

I have a a variable {{ product.amount }} and need to display the amount left of a multiplication of 6.
So for example {{ product.amount }} is 20. so it has to output 4. (for 24)
How can i do this?
You can directly use modulo in twig template, as documentation said :
{{ 6 - product.amount % 6 }}
You can use modulo to calculate the rest of the division by 6 and then calculate the difference
select 6-(20 % 6) as Solved

Can Twig round numbers up to the nearest thousand?

The Twig documentation for number rounding talks about rounding decimals, but I have a case where I want to round a number like 19,995 to 20,000. Is there a tricky way to round up to nearest thousand?
The round filter accepts negative precision. (Just like in PHP)
{{ 19995|round(-3) }}
The simplest way is to divide your original number, round, then multiply again by 1000:
{% set amount = (19995 / 1000)|round %}
{{ amount * 1000 }}
Rounding to the nearest 10k or 100k would be as simple as changing 1000 to 10000 or 100000 respectively.
UPDATE: Or you can just use Matt Rose's suggestion below.
{{ 19995|round(-3) }}

Resources