3

The documentation says:

Snippets are expanded at a very early stage on each template, making it possible for them to hold dynamic content, ExpressionEngine tags, other variables, PHP, etc.

The evidence seems to run contrary to that statement.

Can PHP be used in a snippet as it can in an embed when enabled?

The scenario: I have Google Analytics and other tracking code in a snippet. I want to wrap it in a simple PHP conditional to check for the live site URL, so I'm not hitting that code in my development/staging environment.

Thanks!

Mark

4

Yes, as long as the template in which you put the snippet has PHP enabled.

| improve this answer | |
  • Ah, the template that the snippet is rendered via, because the snippet is just merged in. Got it. As this is a snippet on every page, I'm better off with an embed if I want to do that. Thanks! – Mark J. Reeves May 29 '13 at 21:01
  • @low:can you please give me the syntax of including a snippet in my template?EE docs have only docs showing only embed syntax – user2133 Feb 21 '14 at 7:22

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.