If else to set a new variable in edge template #4068
Unanswered
dmeinke-etc
asked this question in
Help
Replies: 1 comment
-
I tend to use ternaries for simple if/else checks.
You can also create a preload file and add global EdgeJS helpers there, I usually call mine
// start/globals.ts
import View from '@ioc:Adonis/Core/View'
View.global('padDate', (numDate: number) => {
if (numDate > 9) return `${numDate}`
return `0${numDate}`
}) <!-- some view -->
<p>{{ padDate(numDate) }}</p> I also have a lesson that goes into a little more detail on this as well: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
What's the best way to set a variable in an edge template with an if else. I want to pad a number to double digits from a preexisting array. This is what I have and it seems to not process the first
@set
@if(numDate == 1 || numDate == 2 || numDate == 3 || numDate == 4 || numDate == 5 || numDate == 6 || numDate == 7 || numDate == 8 || numDate == 9 ) @set('numDateCalc', '0'+numDate) @else @set('numDateCalc', numDate) @end
I know the best way is to somehow make this array in the controller and I always have previously this is just a different case.
Can I call a function from somewhere to pad the number?
Beta Was this translation helpful? Give feedback.
All reactions