What's the difference between liquid 1.0 and 2.0?

Some of my sites are running slowly and I’ve been advised to switch off liquid 2.0 to increase the speed of the sites.
Other than the differences between nice 1.0 and 2.0 which are bundled into this beta feature, are there other differences between liquid 1.0 and liquid 2.0 implementation?

It’s supposed to render certain liquid code much faster. @Adam.Wilson demonstrated that some time ago with the docs site which is a bit notorious for slow loading due to the abundance of liquid on it. I’m not sure though if Adam has switch 2.0 on this site yet. I think not.

Yeah, docs site is still Liquid 1.0.
In most general cases Liquid 1.0 will work the same as 2.0, but it’s quite different in that 1.0 kinda processed ‘upscope’ while 2.0 goes ‘downscope’ (well that’s how I think of it anyway).
In 1.0 we could pass Liquid variables ‘up’ from a page content area into the head of a template for example. Whereas 2.0 works more like BC did, where variables are passed ‘down’ from template to page - which is more practical I think, but there were cool advantages of it being the other way too.
There are surely many other technical differences in the implementation, but that’s the most prominent difference I think in terms of developing with it.

I’m not sure as yet in what cases 2.0 would be responsible for slower site speed though. I’ve only experienced gains by turning it on so far.

@Alex_B_Centrifuge a good test for you to see the difference…

  1. Create a test page, don’t add a template to it… so just a basic page.
  2. Add <pre>{{this}}</pre>
  3. Preview results.
  4. Test this on both 1.0 and 2.0

Check out results. Not sure if it has been fixed, but check out how much more info is listed (on 2.0).

2.0 seems to be running slower on some of my sites and not on others. Perhaps it is a CA data centre issue (no it is not an implementation issue).

Because 2.0 goes ‘downscope’, putting {{this}} on the page level causes a recursion (using it in the template level is fine though).
So I’m guessing {{this}} will be off limits for use on pages/items, unless they can put some kind of block on the recursion or something???

Yup… but data is data right… way more data == more to load.

Are custom parameters a feature of liquid 2.0 or are they also part of liquid 1.0?

@Alex_B_Centrifuge they are a feature of both 1.0 and 2.0.

1 Like

@Adam.Wilson I’m panicking a bit about the transition from Liquid 1-2 in a weeks time as I only learnt about it in last weeks Treehouse meeting (been under a rock with workload).
I see you contributed to this doc on the subject - https://docs.treepl.co/extras/migrating-from-liquid-version-1-to-2
I hope you don’t mind answering a couple of questions before I go deeper… it is full of typos and I am unclear on a few things - mostly bad use of english that could be interpreted two ways, so I am unsure about the following…

1. Letter case property - this statement seems contradictory:
“This change will not affect property use in liquid implementation because property access in liquid is case insensitive: {{this['ishome']}} and {{this['IsHome']}} would work in both liquids properly regardless the original property name letters case.”
Is it case sensitive or not?

2. Parsing flow - If I have tags in the head or content at pages level that override tags at template level, is Liquid 2 going to use template or the deeper tags to parse the layout?

Of my current live sites, at least 5 of them are riddled with potential conflicts and my old developers walked away from Treepl in favour of SilverStripe, so I have been relying on Treepl Services for a lot of stuff to date. Hopefully they are readily available if these go haywire.

Thanks

Hi @wazzafrog.

Thanks for your feedback on the articles, I’ll try to clean up the wording a bit more for better clarity.

Regarding 1) the Liquid properties are not case sensitive when referenced within Liquid itself. The case of those properties are only sensitive when used in other case-sensitive places, like Javascript/AJAX calls that are referencing those properties (eg: you have an AJAX submitted form and the JS is referencing the response JSON to render any error/confirmation messages or submitted form data)

Regarding 2) Liquid 2.0 flow now works downward through the document render flow (as it did in BC) - so typically from top of Template --> top of Page --> Layout --> bottom of Page --> bottom of Template.
So you can’t pass a variable from the page content to the top of a template, but you can pass that variable to anywhere below itself throughout the document flow, even into the bottom of the template (with the exception of inside other Liquid Layouts where the Liquid reference is in conflict with the Layouts own Liquid scope ie: {{this…}} ).
Liquid 1.0 rendered the Page first then the Template so it could pass Liquid values to any part of the Template. If you need this functionality and can’t achieve it in another way, I may have a workaround if needed (although it’s not ideal).

While the Beta flags are still available in the Beta section of the admin you can experiment by turning it on and see if any issues present themselves, if so, you can turn it off again while investigating the fix required.

Feel free to post any issues here for further help.

1 Like

Thanks @Adam.Wilson, that clears it up. Flow working as BC is desirable, so we should be ok there. We’ll do some experimenting with the beta version to check if we have any AJAX/JS bugs, and let you know if we come undone.