How do you show content on certain day - twig

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' %}

Related

Change the title of the computed webform element conditionally

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?

numbers in HTML component

Hi I create team (It works), but I want to calculate prices. When you choose player (his price is available), I want to subtract from default price. So default price is 100 and if you choose player who cost 5, angular calculate to 95 and then send to database.
extract of HTML of one player:
<mat-form-field>
<mat-select placeholder="Goalkeepers" formControlName="goalkeeper">
<mat-option *ngFor="let player of goalkeepers" [value]="player.id">
{{player.name}} {{player.surename}} ({{player.price}}M)
</mat-option>
</mat-select>
<mat-error *ngIf="form.get('goalkeeper').invalid">Pleasse enter a goalkeeper.</mat-error>
</mat-form-field>
And than I have badget of team:
<p *ngFor="let userTeam of userTeamDetails">
<span *ngIf="userTeam.badget">
Tvoje dostupne peniaze: {{userTeam.badget}}M €
</span>
</p>
I tried to make {{userTeam.badget - player.price}}, but userTeam was not known and I don´t want to see in every player price.
What possibilities I have to calculate this? I don´t have any idea. Thanks.
You can use ng-container in conjunction with ngIf to conditionally display the calculated price only when the team and its budget exists. Example:
<mat-option *ngFor="let player of goalkeepers" [value]="player.id">
{{player.name}} {{player.surename}} ({{player.price}}M)
<ng-container *ngIf="userTeam?.badget">{{userTeam.badget - player.price}}</ng-container>
</mat-option>

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

Add 3 point in the end

I have such html which I use with twig. I tried to print 5 elements with comma
I want add "..." in the end of my tags.
Now it's look like apple, banana, orange, apple, apple, apple
And i want apple, banana, orange, apple, apple, apple, ...
Please, help me to solved this problem
You would need to add your ellipsis conditionally inside the loop.
e.g.
{% if i > 5 %} … {% endif %}

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