How To Access Snippet %(ask) parameters from EJS?

Hello, I’ve been trying to access an ask parameter (interpolation shortcut) from EJS, however I couldn’t yet figure it out where are they stored (if they are). This is inside of the snippet:

protected $[[%ask1:Property Name]];

public function set[[%ask1]]($value)
{
  $this-><%= ask1.toLowerCase() %> = $value;
}

If I’m running this I get a Reference Error ask1 is not defined. How can I access ask1 value from within EJS?

Thank you

You’ll have to pass it through ko.interpolate.interpolateString, eg:

ko.interpolate.interpolateString(["%(ask: Property Name)"])

Reference material:

Thanks. I’ve read those posts several times already and to be honest couldn’t yet easily find out the proper solution.
So in my case this is it:

<%
    ask1 = ko.interpolate.interpolateString(["%(ask1:Property Name)"]);
%>

protected $<%=ask1.toLowerCase()%>;

public function set<%=ask1%>($value)
{
    $this-><%= ask1.toLowerCase() %> = $value;
}

It’s working fine, however this way, in case of multiple ask parameters they all get queried one by one.

Here’s the order of execution:

EJS converts the embedded JS into code for the macro.

The macro is the run through the interpolator, which handles things
like %(ask).

The macro is then executed.

So this is why the EJS phase doesn’t have access to “ask”.

But, much better, it has access to the whole Mozilla/Komodo API,
including ko.dialogs.prompt, best documented by looking at the header
in the actual source

So you can grab a value via ko.dialogs.prompt, or the simpler window.prompt, and use that variable in the macro.

  • Eric

You can also use your own custom ask dialog, for example of a custom UI, see:
http://komodoide.com/blog/2014-02/adding-new-functionality-to-komodo-with-macros/

Broken link