sebastienros/fluid

Including external macros in separate .liquid partial file seems not to work

Opened this issue · 6 comments

If I use macros directly in the same liquid file where I invoke the macros, all macros get executed. If I put the macros in separate .liquid file and import them via the include tag, they are not executed for some reason.
I checked if the separate liquid file is found and read by the fluid template engine and that works fine.

Could you please provide a sample for what you did? So, we can easily reproduce the issue - if there's -

Here is the sample. Please check out the ReadMe.md
FluidIncludeBug.zip

Is it in a public repo? Then write the steps to reproduce the issue

??
I uploaded a complete sample (code and templates).

  • Please unzip the uploaded solution and run the code.
  • In the ReadMe.md I described what to do to see the error.

Ok, you know public repos might be TRUSTED in terms of security ;)

I just had the same issue while I evaluated fluid. I've created a fork and committed a failing unit-test to demonstrate the issue. gebolze@dacd8d6

I did spend a bit more time on the issue. I think the reason for this is the following:
The include statement creates a new ChildScope. The macro statement registers the FunctionValue to the current scope. But once the include is processed the ChildScope is released and together with this the macro is no longer defined.

One way to prevent this could be change the marco statement implementation such that it always registers the value on the RootScope. I've tried this locally and it seems to work, but I'm not familiar enough with the project to decide if this is wanted or not.