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

"Template string" JME data type #423

Closed
christianp opened this issue Jan 13, 2016 · 1 comment

Comments

Projects
None yet
1 participant
@christianp
Copy link
Member

commented Jan 13, 2016

I'm writing a few questions which each have basically the same question repeated several times, with different numbers. The prompt and advice for each is identical, except for the index used on variables holding lists of the corresponding numbers to use.
It would be nice if there was a "template string" data type, which doesn't substitute variables in until it's displayed on the page. There could also be a function eval(template) which would substitute variables into template, using the local scope.
Then my advice section would look like this:

a)
{let(part,1, eval(advice))}

b)
{let(part,2, eval(advice))}

...

and the template would be something like

$x = \var{solution[part]}$

In the editor, maybe the "short text string" and "long text string" data type options should show a checkbox for "this is a template", so it's easy to write. The equivalent JME code would be template("...")

@christianp christianp added the Wishlist label Feb 2, 2016

@christianp

This comment has been minimized.

Copy link
Member Author

commented Apr 4, 2016

render is a much better name then eval for the function which subs variables into a template - I can see people with bad habits abusing a function called eval.

christianp added a commit that referenced this issue Feb 6, 2019

add 'render' JME function
Towards #423.

We already have the 'safe' property for strings, which prevents variable
substitution, so this adds the other end of the process:
`render(str,variables)` substitutes variables into the given string,
adding the given dictionary of variables into the scope temporarily.

`let(variables,render(str))` would be equivalent, but is much less
legible.

christianp added a commit to numbas/editor that referenced this issue Feb 6, 2019

add "is this a template" option to string variables
"short text string" and "long text string" variables have a checkbox "is
this a template?"
If ticked, the string is marked as 'safe', so variables aren't subbed
into it.

see numbas/Numbas#423

@christianp christianp closed this Feb 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.