Open Zucka opened 4 years ago
Ok, thank you for the bug report.
I think it could be fixed in the october sprint.
Any updates on this?
Hello,
I need to make a conditional display. If a product have a specific category I need to display an information.
// My JSON
const json = {
"shopping" : {
"sales": [
{
"product_name": "Apple",
"product_price": 2,
"product_category": "fruits",
"comment": "",
},
{
"product_name": "Coke",
"product_price": 3,
"product_category": "soda",
"comment": "",
},
{
"product_name": "Cucumber",
"product_price": 1.5,
"product_category": "vegetable",
"comment": "",
},
{
"product_name": "Vodka",
"product_price": 15,
"product_category": "Alcohol",
"comment": "Dangerous for health, prohibited at least 18 years old",
},
]
}
What I made on my document : |State | | :------------------------------------------------------------------------------:| |{json.shopping.sales[i].product_name} {json.shopping.sales[i].product_category(“Alcohol”):showBeggin} Information {json.shopping.sales[i].comment}{json.shopping.sales[i].product_category::showEnd}| |{json.shopping.sales[i+1].product_name} |
// OUTPUT expected
Apple
Coke
Vodka Dangerous for health, prohibited at least 18 years old
Is it possible to do this ? Because it's doesn't work and I did'nt find solution … Thank's 🙏
@SekmSet Although that has nothing to do with the issue I originally described it seems that there might be multiple things wrong with your document specification.
So your JSON is malformed. Let's fix that.
{
"shopping": {
"sales": [
{
"product_name": "Apple",
"product_price": 2,
"product_category": "fruits",
"comment": ""
},
{
"product_name": "Coke",
"product_price": 3,
"product_category": "soda",
"comment": ""
},
{
"product_name": "Cucumber",
"product_price": 1.5,
"product_category": "vegetable",
"comment": ""
},
{
"product_name": "Vodka",
"product_price": 15,
"product_category": "Alcohol",
"comment": "Dangerous for health, prohibited at least 18 years old"
}
]
}
}
In Carbone you specify access to the normal Data JSON with "d"
so {d.shopping.sales[i=1].product_name}
would get you the name of the second element in the sales array.
Documentation
One way of doing what you want is the following. ( It at least give the "expected" output you gave )
{d.shopping.sales[i].product_name} {d.shopping.sales[i].product_category:ifEQ('Alcohol'):show(.comment):elseShow()}
{d.shopping.sales[i+1].product_name}
Documentation You can test this with Carbone Studio ( there is a free edition ) https://studio.carbone.io/
Environment Carbone Version: 2.1.0 Node Version: 10.15.0 Browsers: none Desktop OS: Windows 10 - 2004
Expected Behaviour In a showBegin / showEnd section it was expected that other functionality like array repetitions would work. Such that if a paragraf is shown then the included repetitions would work.
Actual Behaviour When a showBegin/End pair is surrounding a repetition it gives an error about not being able to find the ending showEnd tag.
Steps to reproduce Steps to reproduce the bug: See the test data. Normal docx file with test code run directly from cli.
Reproduction Link / Code example Test Data
Test Document:
Test code:
Error:
Other comments Expected output: