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

Get all variables associated with a frame. #35

Closed
danielkjcoles opened this issue Dec 14, 2022 · 3 comments
Closed

Get all variables associated with a frame. #35

danielkjcoles opened this issue Dec 14, 2022 · 3 comments
Labels
question Further information is requested

Comments

@danielkjcoles
Copy link

Bit of a long shot, but I was wondering if there was any functionality that would get all the variables associated with a particular frame?

A bit of context. I have a text frame that contains three short text variables, a long text variable and a list variable. On selecting that text frame I want to get the objects for these five variables. So I can then display custom input fields for these five variables etc.

I'm able to get one of the five variables by setting the variable in the text frame's "Frame Link Settings" in the Chili BackOffice and using the following:

await publisher.addListener("SelectedFrameChanged", async target => {
     const variable = await publisher.getObject('document.selectedFrame.linkSettings.variable');
});

But this is obviously only one of the five.

I'm also aware that I can get all of the variables in the document by using the following:

await publisher.getObject("document.variables");

and then loop through etc as in the Chili Publisher documentation. But I just want the five variables associated with this frame.

I've had a look through the Chili Publisher docs, but I was curious if anything like the following exists:

await publisher.addListener("SelectedFrameChanged", async target => {
     const variables = await publisher.executeFunction("document.selectedFrame","GetVariables");
});

Or if there is any other way to possibly achieve this functionality? Or if I'm going about it in the complete wrong way.

Any help at all would be appreciated.

Cheers

@danielkjcoles danielkjcoles added the question Further information is requested label Dec 14, 2022
@bnzo
Copy link
Contributor

bnzo commented Dec 14, 2022

I guess this is more a support request than a question related to the publisher interface but I use something that might help you:

You can use Private Data Input which allows you to associate name/value pairs to a frame.
You could set into your document frame the following name/values pairs:

variable => 'short text 1'
variable => 'short text 2'
variable => 'short text 3'
variable => 'long text 1'
variable => 'list 1'

Then, you will be able to retrieve them by calling:

await publisher.getObject('document.selectedFrame.privateData[0].name')
await publisher.getObject('document.selectedFrame.privateData[0].value')

You can then compare/associate them to your input values.
If you have many frames, you should make an abstraction to easily make the bond between your private data and your variables.

@danielkjcoles
Copy link
Author

You're probably right, but thanks for the suggestion I'll give it a shot

@seancrowe
Copy link
Collaborator

I am way late to the party, but no there is no way I know of to get all variables in a text frame natively in CHILI

The private data as suggested is a good workaround. Another option is to parse the textflow of a frame for all the variables. You can get the textflow from: await publisher.getObject('document.selectedFrame').textFlow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

3 participants