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

[Feature Request]: "Object type" resolution #186

Open
danibs opened this issue Jun 21, 2023 · 3 comments
Open

[Feature Request]: "Object type" resolution #186

danibs opened this issue Jun 21, 2023 · 3 comments
Assignees

Comments

@danibs
Copy link

danibs commented Jun 21, 2023

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)

@steevepay
Copy link
Member

Hello, did you try using alias?
Documentation: https://carbone.io/documentation.html#alias

@steevepay steevepay self-assigned this Jun 21, 2023
@danibs
Copy link
Author

danibs commented Jun 21, 2023

With the case I proposed, using alias I must define N "identical" alias:

  1. {#A1 = d.myojb}
  2. {#A2 = d.sourse.myobj}
  3. {#A3 = d.dest.myobj}
  4. 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 😄

@danibs
Copy link
Author

danibs commented Jul 4, 2023

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... 😅

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

2 participants