Passing variable to partials in handlebars - handlebars.js

I'm trying to pass a variable to a partials but it doesn't render the passed variable and html code -- is there a way to do this?
e.g.
{{>sayHello text="Hello <b>{{firstName}}</b>!"}}
the partial prints Hello <b>{{firstName}}</b>! instead of Hello Efe!

Related

How to make IPython display work when called from a function

So I understand on a surface level how to render html, using the display function:
IPython.display.HTML('<b>FOOBAR</b>')
But what if I want to create a generic function to dynamically render html (i.e how do I make display work in a function.) For instance:
def foo():
IPython.display.HTML('<b>FOOBAR</b>')
foo() # Does not render anything :(
IPython.display.HTML only creates a display object. It doesn't display it. Such objects are only auto-displayed if the last statement of a cell is an expression statement with such an object as the expression's value.
In any other context, you need to call IPython.display.display to display the object:
def foo():
IPython.display.display(IPython.display.HTML('<b>FOOBAR</b>'))

Can a handlebars partial result be used as a helper's argument?

Can a handlebars partial evaluation result be used as a helper's argument?
I was hoping subexpressions would do the trick, something like:
{{myHelper otherArgument (> myPartial)}}
Needles to say, this doesn't work and I've been scratching my head for other solutions for a while now...
Surely there must be some helper that can evaluate partials?
[edit # 2020-04-04]
The background for wanting this was to be able to interpolate a partial's output into a sentence template by an internationalization hbs helper.
Though #76484's suggestion comes close to a viable solution, I've already admitted defeat because, while an answer was pending I tried recreating the partial as an hbs helper and found that no amount of Handlebars.SafeString(...) wrapping can prevent the result from getting escaped anyway after it was interpolated; so, short of modifying the i18n helper itself, it's not going to fly.

Robot framework: Assigning variables from a dictionary

I have a scenario in which I would have to read from a dictionary and create variables with key as the variable name and value as the variable's value.
For example, if "hello": "world" is a dictionary item, then I have to set hello = world. This variable also needs to be later called in a test case. I tried to achieve this via below method but not sure if it has the right syntax and anyway it fails with No keyword with name '${$k}} found error.
Can anyone let me know if this can be done?
*** Keywords ***
Spin Variables
${items}= get dictionary items ${arg}
:For ${k} ${v} IN #{items}
\ ${${k}}= set variable ${v}

Variable initialization from things included via use/only

I would like to create a variable in a module from quantities I've imported from another one. All the functions in this module will use the new variable, so I would prefer not to have to declare and assign it anew in every function. I'd like to declare and assign it once at the start and have it global to the entire module. But this does not work:
module example_mod
use some_constants, only:derp, blah
implicit none
real, private :: derived_const = derp*(blah-1.0)/50.0 !doesn't work!
contains
!a whole bunch of functions that use derived_const
How can I get what I want?
The compiler is telling you that "derp" should be a constant. You can make it one by adding to its declaration the specifier parameter. This is also safer for constant variables because it will prevent the programmer from accidentally changing them.

How does zope/plone evaluate variables?

Imagine this scenario:
I have a ZPT in Zope where I define, into a metal block, a global variable.
This variable takes its value from an expression like this
global myVar id | nothing;
global anotherVar 1;
where nothing could be replaced with python:0 or python:False or None and so on.
Now imagine that into another block, I'll do something like
global myVar2 myVar | anotherVar | nothing;
where nothing could be everything that I specified above.
Now suppose that id hasn't a value and so myVar took nothing (or the other possible values; it's makes not difference at all).
What I expected was that myVar2 took anotherVar's value, since anotherVar has a value. But with great surprise, I notice that this isn't true and myVar2 took myVar value; that means nothing.
If I understand what is happening, I'll suppose that this kind of statement only control over existence of that variable and not over it's value.
Obviously I can make that kind of statement into a pythonic way and, of course, it works "well" (namely, as I expected)
So, someone can confirm or disprove what I suppose there ?
What you are asking is not Plone or Zope specific, you are dealing with a TALES statement here, which, together with TAL and METAL form the page template language implemented by Zope Page Templates (and, incidentally, also by chameleon, plus several other implementations in different programming languages).
You are using a TALES path expression when you use the | character, and it is not the same as a Python or expression. Each path named in the expression will by resolved, and only if it doesn't exist will the next path be used. From the specification:
When a TALES path expression is evaluated, it attempts to traverse each path, from left to right, until it succeeds or runs out of paths.
Since all your paths resolve to existing variable names, they all exist and the first one will be used, regardless of it's value.
You want to use a python: expression instead:
myVar2 python:myVar or anotherVar or None;
Note that in TAL there rarely is a need for the global keyword. You probably want to define these items on your root element of your document instead; variables are visible within the same scope as the XML or HTML element they are defined on:
<html tal:define="myVar id | nothing; anotherVar 1;">
<!-- myVar and anotherVar are visible in the whole HTML document -->
</html>

Resources