0

Is it ok to use an early parsed variable/snippet with the following inside?

logged_in AND member_group == "1" OR member_group == "2" OR member_group == "3"

So that i can use the following at the top of my template

{if {variable}} Content {/if}

It works.... I just want to know if its bad practise or comes with any issues etc? If it is a problem, can anyone suggest another way i can lock down my templates but have one place that I can edit the statement if anything changes. This would save me changing it on every template.

1

All a snippet will do is place the content assigned to it before it parses the template.

So your original template will look like this:

{if {variable}} Content {/if}

Then once the snippet is parsed it will look like this:

{if logged_in AND member_group == "1" OR member_group == "2" OR member_group == "3"} Content {/if}

Then it will parse the template properly.

It's not bad practise as that was the main purpose of snippets in EE versus variables (which aren't able to be parsed directly, only their value is used).

Negatives regarding Snippets are that it's easier for other developers to get lost - naming all your variables and snippets with a prefix helps avoid this so when you see the code used (e.g. {tag}), you know if it's a tag variable {tag}, snippet {snp_tag} or variable {var_tag}.

Also there is a technical debt - have a read of this acticle that explains it extremely well.

1
  • Amazing Peter, thanks so much for that response! Great tip as well! – Third_Hyperion Sep 24 '15 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.