New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divide by 2 not working #1319

Closed
colinmeinke opened this Issue Mar 13, 2017 · 16 comments

Comments

Projects
None yet
4 participants
@colinmeinke

colinmeinke commented Mar 13, 2017

---
num: 10
---

{{ num|/:2 }} <!-- outputs: 10 (incorrect) -->
{{ num|/:2.0 }} <!-- outputs: 5 (correct)-->
{{ num|/:4 }} <!-- outputs: 2.5 (correct) -->

Statamic 2.5.3

@DavidStrada

This comment has been minimized.

DavidStrada commented Mar 13, 2017

have you tried {{ num divide="2" }} ?

docs

@colinmeinke

This comment has been minimized.

colinmeinke commented Mar 13, 2017

@DavidStrada same issue

@jackmcdade jackmcdade self-assigned this Mar 16, 2017

@jackmcdade

This comment has been minimized.

Member

jackmcdade commented Mar 16, 2017

I've tried every variation of this without an issue. I'm trying to think of a case where the data can be treated differently but am coming up short. I tested (in 2.5.5):

  • in a template with the data in an entry
  • in a template with data in the template's front matter
  • in an entry's front-matter with the tags in the content
  • both regular and a param style syntaxes

Is there anything else you can share about how you're using this?

@colinmeinke

This comment has been minimized.

colinmeinke commented Mar 16, 2017

I can strip out everything from the template apart from the code above, and use a layout that has nothing but {{ template_content }}, and still get this error. Upgrading to 2.5.5 has not made a difference. PHP 5.6.27 locally, 7.0.8 on production, both with the same error.

@jackmcdade

This comment has been minimized.

Member

jackmcdade commented Mar 16, 2017

@DavidStrada

This comment has been minimized.

DavidStrada commented Mar 16, 2017

@colinmeinke Why don't you download a fresh installation ? and use that one as your "new". copy/paste code from your previous one ( production code ).

As opposed to keep fighting against something that it appears to be time consuming.

@colinmeinke

This comment has been minimized.

colinmeinke commented Mar 17, 2017

@DavidStrada I filed this issue because Statamic might want to aware of a bug, in a real world use case, where something as fundamental as division by 2 is failing. I have already worked around it by dividing by 2.0 instead of 2. A hack. But starting again and hoping it doesn't reoccur isn't a solution. It's happening for a reason, and if that isn't found then it could happen again to somebody else.

@colinmeinke

This comment has been minimized.

colinmeinke commented Mar 17, 2017

I have found the reason this is happening. The content file has two lines at the beginning, that when removed fixes the issue:

0: integrate
1: integrate
template: integrate
id: 235ca2cd-d26b-4a59-9aa9-cb8dc738f41d

@jackmcdade when, and why do these lines get added to the content file?

If I add two more lines in there:

2: integrate
3: integrate

This also breaks division by 3 and 4.

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented Mar 17, 2017

I had a feeling that was the reason. I don't know how your data ended up like that, though.

The divide modifier will take the parameter and resolve it from context.

For example:

---
num: 10
things: 2
---
{{ num | /:things }}

It resolves things to 2. This would be 10 / 2 = 5.

In your case, 2 corresponded to integrate. This would be 10 / "integrate"

I don't have a solution for you right now, other than using 2.0 or removing the weird data, but I'm just explaining what happened.

@jackmcdade jackmcdade added not a bug and removed can't recreate labels Mar 17, 2017

@jackmcdade

This comment has been minimized.

Member

jackmcdade commented Mar 17, 2017

There isn't much we can do to change the behavior short of a breaking change, but we'd be happy to help you find a workaround. Since this isn't a bug tho, I'm going to close the issue. 👍

@jackmcdade jackmcdade closed this Mar 17, 2017

@colinmeinke

This comment has been minimized.

colinmeinke commented Mar 19, 2017

Looking at the commits, these additions were made when the client was interacting with the control panel. Not sure how this doesn't classify as a bug, if by interacting with the control panel UI a client can break division by x on a page. Unless you're saying this is expected behaviour, and accept and are happy that this can happen in certain cases? This could be pretty serious if the division is used to display financial information, for example. In our case it lead to the images displaying at twice the desired size - not critical, but not great.

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented Mar 28, 2017

The division part isn't a bug. The cause of how the data got to that state is, though.

@colinmeinke

This comment has been minimized.

colinmeinke commented Mar 28, 2017

@jasonvarga yep sure, but there is an issue here - changes on production (by the client interacting with the admin UI) have added 6 additional indexed lines at the beginning of this content file. Now division up to 8 is broken, and additional images on the page are broken.

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented Mar 28, 2017

I get that. The data should never be getting saved like that, though. You should open a separate issue regarding that, specifically. Include the fieldset, etc.

@colinmeinke

This comment has been minimized.

colinmeinke commented Mar 28, 2017

Feel free to open another issue if you want. In my opinion this issue is sufficient. A function is broken, it doesn't matter if the function is directly the cause or if it's an issue deeper down. It's related.

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented Mar 29, 2017

This is fixed changed for next release.

It'll only fetch the value from context now if it's not numeric.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment