Multiple transclusion

From Wikipedia

When the Lua function frame:expandTemplate is used, this doesn’t create the new frame corresponding to the template expansion, but affect to the expanded template the "top" frame.

I
  1. (here: FirstTemplate, parentFrame:Template:FirstTemplate)
  2. (here: SecondTemplate, parentFrame:Template:SecondTemplate)
  3. end
II
  1. (here: FirstTemplate, parentFrame:Template:FirstTemplate)
  2. (here: SecondTemplate, parentFrame:Template:SecondTemplate)
  3. end

In {{FirstTemplate}}, Lua is invoked in the case I to "expandTemplate" {{SecondTemplate}}, and in the case II to "preprocess" {{SecondTemplate}}.

When frame:getParent():getTitle() is called in each template, the case II always returns the caller of #invoke, but in the case I the second transclusion shows the top frame (this page) as the caller of #invoke.