Page 1 of 1

Creating $ask with answer from a previous $ask

Posted: Thu Oct 17, 2019 12:22 pm
by JulieP
I'm creating a template where I ask for a product name that will be reused with an ID of name:
${answer(@name)}

I want to reuse the key as part of another ask. I set up this ask with radio buttons for two different possible sentences that can be inserted, depending on the option that the writer picks. The name needs to be reused in both sentences. This is the $ask I've set up:

${ask('How is the product activated?', radio, (

'<p>${answer(@name)} is active by default.</p>'
:'It is active by default';

'<p>${answer(@name)} must be enabled with a plugin.</p>'
:'It must be activated with a plugin'))}

With the $answer variable, the dialog box for this $ask doesn't render properly. The dialog box displays with Cancel and OK buttons, instead of radio buttons with the answers I've listed above.

Re: Creating $ask with answer from a previous $ask

Posted: Thu Oct 17, 2019 2:21 pm
by alex_jitianu
Hello,

What Oxygen version are you using? In version 21.1 we introduced an improved version of the engine that expands editor variables. In version 21.1, a document template content like this expands correctly:

Code: Select all

${ask('message', generic, 'default_value', @name)}

======

${ask('How is the product activated?', radio, (

'<p>${answer(@name)} is active by default.</p>'
:'It is active by default';

'<p>${answer(@name)} must be enabled with a plugin.</p>'
:'It must be activated with a plugin'))} 
The only requirement is for the @name ask to appear first in the document template.

Best regards,
Alex

Re: Creating $ask with answer from a previous $ask

Posted: Fri Oct 18, 2019 8:05 pm
by JulieP
Hi Alex,

We're using Oxygen v20.1.

Re: Creating $ask with answer from a previous $ask

Posted: Mon Oct 21, 2019 11:25 am
by alex_jitianu
Hi,

For version 20.1, you could create an Oxygen plugin for such an use case. You would have to define custom variables and use them inside the template. Afterwards, from the plugin, you can add an EditorVariablesResolver that looks in the content for the variables and knows what to ask the user and how to combine the responses.

The sample-plugin-workspace-access is a good starting point. You add that resolver like this:

Code: Select all

  /**
   * @see ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension#applicationStarted(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace)
   */
  @Override
  public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {
	  pluginWorkspaceAccess.getUtilAccess().addCustomEditorVariablesResolver(new EditorVariablesResolver() {
		  @Override
		public String resolveEditorVariables(String contentWithEditorVariables, String currentEditedFileURL) {
			// TODO Replace variables
		  return super.resolveEditorVariables(contentWithEditorVariables, currentEditedFileURL);
		}
	});
Best regards,
Alex

Re: Creating $ask with answer from a previous $ask

Posted: Mon Oct 21, 2019 7:12 pm
by JulieP
Thank you, Alex!