Scoping question, define new variable in template for block on page, is it page-wide?

Okay, so scenario.

I have a page with a bunch of blocks, Express blocks and other things. Let’s say I make a template (and apply it) to an Express Entry List block on a page.

At the top of the template, before the template starts doing its “if ($entity)…” stuff, if I define a variable there (outside of any loops, braces, or whatever) in said template, and then that template is applied to a block on a page… is that variable only usable within that specific block on that page? Or does the variable exist for the other blocks on the page too? (as well as the actual value of that variable).

I’m asking to try and plan around the expected behaviour. As if the variable is readable/writable by other blocks on the same page, well then I need to expect that and plan accordingly.

So what is the actual behaviour and/or expected behaviour in this case?

Thanks!

Such variables will not be globally available.

Easiest trick is to create your own class with set and get methods containing a static variable that you can use to communicate between your blocks.

You will need to be very careful about relying on any block-to-block data dependency. There will be situations when block2 is rendered without block1 being rendered first. Think about cache, edit mode, any ajax rendering.

@JohntheFish thanks for clarifying! I actually did not want the variables to be global, hehe. But wanted to ask, just so I could avoid accidentally making them global. As I reuse the name of the variable from one block to another sometimes, and didn’t want “unexplainable” outcomes, hehe.

Love your work! And yeah, appreciate your help here. :slight_smile: