carbone
carbone copied to clipboard
[Feature Request]: "Object type" resolution
Hi Suppose to have:
{
"descr",
"myobj": {
"a": "aa1",
"b": "bb1"
},
"source": {
"type": "t1",
"myobj": {
"a": "aa2",
"b": "bb2"
}
}
"dest": {
"type": "t2",
"myobj": {
"a": "aa3",
"b": "bb3"
}
},
"arr": [
{
"t": "ttt",
"myobj": {
"a": "aa4",
"b": "bb4"
}
},
{
"t": "yyyy",
"myobj": {
"a": "aa5",
"b": "bb5"
}
}
]
}
as you can see myobj
is present in different places.
For all places I must repeate placeholders (in my template):
{d.myobj.a}-{d.myobj.b}
{d.sourse.myobj.a}-{d.sourse.myobj.b}
{d.dest.myobj.a}-{d.dest.myobj.b}
...
If what I want to print is always:
{*.a}-{*.b}
it might be useful to have some sort of "function":
f:myfunc(elem)
{f.myfunc(d.myobj)
{f.myfunc(d.souce.myobj)
Hello, did you try using alias? Documentation: https://carbone.io/documentation.html#alias
With the case I proposed, using alias I must define N "identical" alias:
-
{#A1 = d.myojb}
-
{#A2 = d.sourse.myobj}
-
{#A3 = d.dest.myobj}
- case for array
and then use it repeating what I want:
{$A1.a}-{$A1.b}
{$A2.a}-{$A2.b}
{$A3.a}-{$A3.b}
What I mean is a kind of function to which I pass the path to myobj
and that function compose the text I need.
What do you think about?
It could be that it is only needed for very specific cases, so you don't need to implement it. It's just an idea :smile:
Also, right now alias is not so powerfull. I'm building an example where I have an array and in a cell I need to show a concatenation of two fields (i.e. "a vs b") if another field "c" is "true", but if "d" is "true" then I must show "e". Doing that in a kind of function (or a super-power alias 😉) can help when you must modify the document template... 😅