I’m trying to get simple PHP to execute within a channel field. I have wygwam field, that when I add this to the source
<?php
echo 'test';
?>
then submit the entry, the code is rendered like this:
<!--?php
echo 'test';
?-->
I have no restrictions set in the wygwam field, the template that the channel is using has php set to on. Is this not possible?
I’m trying to get simple PHP to execute within a channel field.
Can you tell me what the reason is? I feel like there must be a better way to accomplish what you’re after and I’d love to help you get there. I can’t imagine that that would work inside of Wygwam, I’m sure CKEditor is doing something there. In general though, putting PHP into entry content isn’t a great idea, though it would work with first-party textareas without field formatting on a template that had output PHP parsing enabled.
Honestly, I try to steer people away from putting PHP in templates, so for me this is one step further away from ideal.
The reason is pretty much this http://cantonbecker.com/etcetera/2015/how-to-use-mailchimps-archive-js-code-if-your-site-is-ssl-encrypted/
That has a php hack to get the mailchimp archive feature working on ssl encrypted pages.
I figure I’ll just add the php to the template instead and only fire it on
{if last_segment =="mysegment"} php code here {/if}
Instead of within the channel field.
Ah, yeah. Best not to be entry content. That said, creating a simple plugin to do this would be trivial, and allow you to keep PHP processing off in your templates. There are measurable performance, security, and maintenance incentives to do so. Let me know if you need pointing in the right direction!
Yep, super easy! Once you have working PHP, you will basically move it to a plugin file and add an addon setup file.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.