Creating $ask with answer from a previous $ask

<oXygen/> general issues.
JulieP
Posts: 11
Joined: Sat May 30, 2015 2:18 am

Creating $ask with answer from a previous $ask

Post by JulieP » Thu Oct 17, 2019 12:22 pm

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.

alex_jitianu
Posts: 704
Joined: Wed Nov 16, 2005 11:11 am

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

Post by alex_jitianu » Thu Oct 17, 2019 2:21 pm

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

JulieP
Posts: 11
Joined: Sat May 30, 2015 2:18 am

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

Post by JulieP » Fri Oct 18, 2019 8:05 pm

Hi Alex,

We're using Oxygen v20.1.

alex_jitianu
Posts: 704
Joined: Wed Nov 16, 2005 11:11 am

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

Post by alex_jitianu » Mon Oct 21, 2019 11:25 am

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

JulieP
Posts: 11
Joined: Sat May 30, 2015 2:18 am

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

Post by JulieP » Mon Oct 21, 2019 7:12 pm

Thank you, Alex!

Post Reply