Skip to content
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

Conditional TSS treats floating point zero as blank #218

Open
cj-clx opened this issue Oct 1, 2019 · 4 comments
Open

Conditional TSS treats floating point zero as blank #218

cj-clx opened this issue Oct 1, 2019 · 4 comments

Comments

@cj-clx
Copy link

cj-clx commented Oct 1, 2019

It would be nice if the following worked as expect, displaying the value $0.00 instead of leaving the XML unaltered.

<?php
require "vendor/autoload.php";

$xml = '<span>FAILS</span>';

$tss = 'span:[data(foo)!=""]  { content: "$", data(foo); } ';

$data['foo'] = 0.00;

$template = new Transphporm\Builder($xml, $tss);
echo $template->output($data)->body . PHP_EOL;

I have frequent need for this kind of check in my TSS code because the application service classes I'm calling don't always return every data element.

Is there perhaps a work-around I don't know about?

@garrettw
Copy link
Contributor

garrettw commented Oct 1, 2019

You would need to run the number through a formatter first, which would convert it to a string.
Take a look at this wiki page: Formatting data

@cj-clx
Copy link
Author

cj-clx commented Oct 1, 2019

My example above was perhaps a bit too limited. The data value is a floating point number in my real application, and my TSS (with my current work-around) looks like this:

/* Do not try to display missing values. */
td span.amount:[data(output.paid_amount)!=""] {
    content: "$", data(output.paid_amount);
    format: decimal 2;
}
/* DO display zero values. */
td span.amount:[data(output.paid_amount)=0] {
    content: "$", data(output.paid_amount);
    format: decimal 2;
}

@TRPB
Copy link
Member

TRPB commented Oct 3, 2019

In the example above, you're doing the same thing for both situations, 0 and not null. Do you want different behaviour on both null and 0.00?

@cj-clx
Copy link
Author

cj-clx commented Oct 3, 2019

Yes, I think that's the crux of the issue. The API I'm calling returns a numeric currency amount as 0.00 through (say) 9999.99, OR it will not return the currency element at all. When it is zero or other numeric, I want to format it nicely. Otherwise, I don't want to display anything, e.g. thus leaving out a lone $ symbol.

Am I making it clear now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants