Closed (works as designed)
Project:
Drupal core
Version:
8.1.x-dev
Component:
theme system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
4 Oct 2016 at 21:23 UTC
Updated:
6 Oct 2016 at 16:35 UTC
Jump to comment: Most recent
Comments
Comment #2
wesruv commentedIf you change the first invocation of the macro to pass '0' (a string, instead of a number) and check for '0', that if statement will come back true.
We don't want to do that though, so I also tried:
|number_formatby default will strip off all decimal places. This worked, but seems odd that I have to do this.Unsure of the best way to fix this, is appending
|number_formatacceptable for core?Would it be better if we fixed something in twig so that 0 was an integer and didn't become a float (I'm assuming that's what's happening)?
Comment #3
cilefen commentedPerhaps try sameas for a strict comparison.
Comment #4
joelpittetDo you know where it's made a string?
Comment #5
wesruv commentedBlurg! This was my bad, I was convinced that the issue was that if statement.
The thing that got me debugging was a var I declared with
{% set ... %}outside of the{% macro ... %}inmenu.html.twig. It looks like the variables declared outside of in the same file macro don't make it inside.In my debugging I was convinced 0 was getting turned into a float and == wasn't evaluating correctly.
Seems a bit odd that variables don't make it inside of macro's, but I suppose there's a reason. Not sure there's anything to do to alleviate confusion. Maybe Sensio Lab's docs page could mention how scope works in macro's, but that's nothing for us to do differently.
Sorry!
Comment #6
wesruv commentedComment #7
wesruv commentedMade documentation ticket in Sensio Labs docs since I could find anything documenting how scope works with macros.
https://github.com/twigphp/Twig/issues/2171