Looks like you are mixing up SSJS and AMPscript. AMPscript blocks begin and end with %%[ and ]%%
Also instead of using ContentAreaByName, set the variable to be the External Key and use ContentBlockByKey. For example,
set @footerBlock = '[ContentBlockKeyHere]`
if @flag == '1' then
%%[ else ]%%
You should just ditch the dynamic content modules and script your blocks with AMPscript.
I'd suggest an init placeholder in your template or a simple code block at the top of your email. Assuming you can relate to your new data extensions via the sendable field, you can supplement the send context by doing a lookup and setting a new set of AMPscript ...
See Salesforce's documentation on this.
If you're updating AMPscript, the documentation states that you need to pause and republish its associated triggered send via Interactions > Triggered Sends > Journey Builder Sends. Once you've updated your email, do the following:
Navigate to Interactions > Triggered Emails > Journey Builder Sends, to ...
Transactional Send Classifications:
Ignore Status "unsubscribed" on the All Subscribers List and send anyway. (They do respect status "held".)
do not feature a list-unsubscribe header in the Email headers.
Commercial Classifications do the opposite. (and of course also respect "held" status)
In short: You cannot unsubscribe ...