I use curreny pipe, but it add digits after dot.
How to remove them?
The result of {{ 1111111 | | currency:'ILS' }} is 1,111,111.00.
I want to remove the ".00"
I tried to use both pipes, curreny and number:
{{ 1111111 | number: '2.0' | currency:'ILS' }}
but it don't give any result.
Try this
{{ 1111111 | currency:'ILS': 'symbol':'1.0-0' }}
symbol will remove zero's.
Please read the documentation is really explained in details. https://angular.io/api/common/CurrencyPipe
Happy coding
Related
#views.py
.
.
.
detailedStatement = {
'selectedOption1' : '90 degrees',
'correctAnswer1' : '180 degrees',
'selectedOption2' : 'angle',
'correctAnswer2' : 'side'
}
#Above dictionary contains 200 elements
diction = {
'detailedStatement' : detailedStatement
}
return render(request, "result.html", diction);
So while on an html file I wanted to access the dictionary's every element via a loop. Like every element should be listed in the html table row like following.
| Sr | Selected Option | Correct Answer |
| 1 | 90 degrees | 180 degrees |
| 2 | angle | side |
Above table is just a representation of html table not an actual table.
But the issue I am facing is... I am not able to access its index in a dynamic way.
I wrote a for loop in Django html template but
{% for dr in detailedResult.items %}
<tr>
<td>{{forloop.counter}}</td>
<td>{{dr.option.forloop.counter}}</td>
<td>{{dr.answer.forloop.counter}}</td>
</tr>
{% endfor %}
I want my code to automatically put 1 after option and answer like option1, answer1;
How can we do this?
I think you should model this with a list instead of including an index in your variable names, e.g.
# views.py
detailed_statements = [{'option': '90 degrees', 'answer': '180 degrees'}, ... ] # contains 200 elements
Then in your template
{% for dr in detailed_statements %}
<tr>
<td>{{forloop.counter}}</td>
<td>{{dr.option}}</td>
<td>{{dr.answer}}</td>
</tr>
{% endfor %}
I was a bit confused by the nested for loops in your template code - I think you only need one?
I have the following code where I need to make the profile.userId bold:
<p class="profile__last-login" *ngIf="profile.lastLoggedIn">
{{'intranet.profile.dashboard.lastLoggedIn' | messageBundle: profile.userId + ',' + (profile.lastLoggedIn | date: 'MM/dd/yyy h:mma') }}
</p>
When displayed on the page, it should say "User (username), last logged in on MM/dd/yyy h:mma" with the username in bold, but I'm not sure how to style the profile.userId within a binding?
You could split the text field. You do not need to keep the binding all together. However, I'm not quite sure what's happening with your pipes so this may not work. My guess is that you should simplify your pipes so that you can break up the text portion as below:
<p class="profile__last-login" *ngIf="profile.lastLoggedIn">
<b>{{'intranet.profile.dashboard.lastLoggedIn' | messageBundle: profile.userId }} </b>
, {{ (profile.lastLoggedIn | date: 'MM/dd/yyy h:mma') }}
</p>
Hello I can't find the way for doing this correctly :
{{point.localized ? "{{ 'CHECKED' | translate }}" :"{{ 'I_AM_HERE' | translate }}" }}
point.localized is a boolean and if it's true I want to display the translation for checked and if it's not the translation for I_AM_HERE how can I do this ?
What about this:
{{(point.localized ? 'CHECKED' : 'I_AM_HERE') | translate }}
Try this:
{{point.localized ? ('CHECKED' | translate) : ('I_AM_HERE' | translate) }}
Or the long way around, which is still valid:
<div ng-if="point.localized">
<span>{{'CHECKED' | translate"}}</span>
</div>
<div ng-if="!point.localized">
<span>{{'I AM HERE' | translate"}}</span>
</div>
I created a new template and want to display a list inside my newly coded infobox. To get this working I was told to change the code like in this German tutorial.
This is how my template Infobox Music currently looks like:
|-
{{#if: {{{Sänger<includeonly>|</includeonly>}}} |
{{#ifeq: {{Str left|{{{Sänger}}} }} | *
|{{!}} style="vertical-align:top;" {{!}}
'''Sänger/in'''
{{!}}
{{{Sänger}}}
|{{!}} '''Sänger/in'''
{{!}} {{{Sänger}}}
}}
}}
In order to build a new list I edited the source code in a seperate Wiki entry like this:
{{Infobox_Music
|Sänger =
* Lady Gaga
* Michael Jackson
}}
Unfortunately, when using both of these settings my list gets displayed with the first item having an * at the beginning just as usual. Here is how it looks in HTML:
<tr>
<td> <b>Sänger/in</b>
</td>
<td> * Lady Gaga
<ul><li>Michael Jackson</li></ul>
</td></tr>
Did I miss something? What does the line {{#ifeq: {{Str left|{{{Sänger}}} }} mean?
UPDATE: Here is a snippet of my previous Infobox Music template:
{{Infobox Music
|-
{{#if: {{{Sänger|}}} | {{!}} '''Sänger/in''' {{!!}} {{{Sänger}}} }}
}}
{{Str left|{{{Sänger}}} }} is the first character of the Sänger parameter (see {{Str left}}). {{#ifeq: {{Str left|{{{Sänger}}} }} | * | ... is some kind of horrible hack to use a different layout when the parameter is a list; not trying to replicate that will help you preserve your sanity.
* will only be interpreted as a list when preceded by a newline. You can prevent stripping of the leading whitespace from the template parameter by doing something like
|Sänger = <!---->
* Lady Gaga
or you can make sure that in the template {{{Sänger}}} is preceded by a newline.
I'm using the MediaWiki extension DynamicPageList (third-party) which can be used as a template:
{{#dpl:
|category=foo
|notcategory=bar
}}
I try to use this template in one of my templates which uses more parameter e.g.:
{{myTemplate
|category=foo
|notcategory=bar
|mypara1=bla
|mypara2=lala
}}
myTemplate looks like this:
do something with mypara1
...
do something with mypara2
...
{{#dpl:
|category=foo
|notcategory=bar
}}
I know my parameters but #dpl: can use one or many parameters.
How can I separate my parameters from the #dpl: ones? And how can I just hand over the parameters which belongs to #dpl:?
Thanks,
Ray
Finally I came up with the following solution:
DPL has an additional template #dplreplace. I'm using this to parse my parameters.
Call the template:
{{myTemplate
| filter=category:foo;notcategory:bar
| mypara1=bla
| mypara2=lala
}}
In the template I replace the : by = and ; by {{!}}.
{{#dpl:
| {{#dplreplace: {{#dplreplace: {{{filter}}} | /:/ | = }} | /;/ | {{!}} }}
| ordermethod = sortkey
| suppresserrors = true
}}
NOTE: {{!}} is a template which is replaced by |.
Regards;
Ray
Maybe I'm misunderstanding your issue, but you can just pass the parameters on to DPL, just like you would to a template, or another parser function. You might want to add an empty default in most cases:
myTemplate:
do something with {{{mypara1}}}
do something with {{{mypara2}}}
{{#dpl:
|category = {{{category|}}} <!-- default to empty string -->
|notcategory = {{{notcategory|}}} <!-- default to empty string -->
}}
Call it like this:
{{myTemplate
|category=foo
|notcategory=bar
|mypara1=bla
|mypara2=lala
}}
Will work with missing parameters too:
{{myTemplate
|category=foo
|mypara1=bla
|mypara2=lala
}}