Forum

Thread tagged as: Question

How can I enter PHP in a "code block"?

Is there any way to allow the manual addition of PHP into a "code block" region? Currently it's just commented out in the code.

Thanks!

James B

James B 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't enter PHP anywhere via the control panel.

James B

James B 0 points

Drew McLellan said:

You can't enter PHP anywhere via the control panel. Is there no work-around at all? Creating a custom template of some sort, or anything?

I'd really like to be able to include some PHP in some pages but not others, but it would be different each time.

Thanks.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello James,

Besides the fact that you can't, your PHP code is best placed in your codebase, not your database. You generally would want to be able to maintain and version control your code.

I'd really like to be able to include some PHP in some pages but not others, but it would be different each time.

Is there any reason why you can't do that directly on your PHP files?

If you can explain what you are ultimately trying to achieve, we may be able to help you come up with a more suitable solution.

James B

James B 0 points

Is there any reason why you can't do that directly on your PHP files?

If you can explain what you are ultimately trying to achieve, we may be able to help you come up with a more suitable solution. I'm using Perch to create landing pages; while a template generally works for most of what I want, on some pages I'd like to accept and echo out variables that are set within a region. I guess I'll have to find another solution.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can still do stuff in PHP and inject it into the templates, you just can't key PHP into a content field.

James B

James B 0 points

Drew McLellan said:

You can still do stuff in PHP and inject it into the templates, you just can't key PHP into a content field.

No problem, thanks for the replies. I know what I want to do is a bit hacky, would just be super convenient ;)

Thanks again guys.