We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

PHP commented out in entry

Development and Programming

skodaminotti's avatar
skodaminotti
105 posts
9 years ago
skodaminotti's avatar skodaminotti

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?

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones
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.

       
skodaminotti's avatar
skodaminotti
105 posts
9 years ago
skodaminotti's avatar skodaminotti

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.

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

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!

       
skodaminotti's avatar
skodaminotti
105 posts
9 years ago
skodaminotti's avatar skodaminotti

I’ve never created a plugin before 😊 If you can point me in the right direction on how to get started that’d be great!

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

Yep, super easy! Once you have working PHP, you will basically move it to a plugin file and add an addon setup file.

  • Constructing a plugin
  • addon.setup.php File
       
skodaminotti's avatar
skodaminotti
105 posts
9 years ago
skodaminotti's avatar skodaminotti

great, thanks! Actually those are both the same links?

       
Derek Jones's avatar
Derek Jones
7,561 posts
9 years ago
Derek Jones's avatar Derek Jones

Whoops sorry, updated my links.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.