How to merge some parts of my code, that run only within some logical tests

I have a trigger on/off. I want a large part of my code running only when trigger is on. Nevertheless using “if” function leaves me with no other option but to recall it for each expression I use.
This is a naive example to point out what i mean:

t = 0;

If[t == 1,

 test1 = Log[23]

 ]



If[t == 1,

 test2 = test1*3 + 45

 ]


setting t==1 (on, runs my code. test1 is initialized. Then I do the same thing with test2 (i mean, repeating the “if” check).

is there any way to run all my code within one “if”?

How about defining a function that performs the tasks you want to switch on or off and putting a call to that function in your If statement?

how am i supposed to do that in my example? any idea?

in real life, I have lots of stuff going on, much more complicated expressions that test1 and test2 in my previous example.

Isn’t this what you need?

If[
 t == 1,
 test1 = Log[23];
 test2 = test1*3 + 45;
 ]

Small suggestion: it is often better to use === as opposed to == as in,

If[
 t ===1,
 test1 = Log[23];
 test2 = test1*3 + 45;
 ]