06.
If Statements with "Tests"
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
6 Comments
In the challenge #2 I've written condition like this
{% if quantityRemaining is defined and quantityRemaining <b>is even</b> %}And it showed me an error, that the expected code was
{% if quantityRemaining is defined and quantityRemaining <b>is not odd</b> %}It will be great if you allow the first option to pass validation :)
Hey horlyk!
Ha! Great point - thanks for telling us - we'll see if we can make that grading a bit smarter. Your "is even"... even looks better ;).
Cheers!
It is worth mentioning here that default filter is an alternative to if else statements. http://twig.sensiolabs.org/...
{{ backgroundColor|default('lightblue') }}
Yes! That's a clever way to use the default filter indeed! You can also do {{ backgroundColor ? backgroundColor : 'lightblue' }}, but in this simple case, default is way cooler :p
Cheers!
There's a typo in the Answer to Challenge #2 after this video - line #6 on _layout.twig should be 'quantityRemaining' not 'quantityRemaning' (it's missing an 'i' in the variable name)
Hey Goz,
Wow, it was difficult to find but you nailed it, good work! Thanks for this report, I fixed it in https://github.com/knpunive... with our internal tool.
Cheers!
"Houston: no signs of life"
Start the conversation!