Jump to content

Add PHP include to field


Peter Knight
 Share

Recommended Posts

Does ProcessWire support PHP includes when they are called from a text field?

I've created a field called Inject Include and added a PHP Include call within that.

post-1166-0-38878200-1414146039_thumb.pn

Right now, the ouput on the front end is my PHP include wrapped in HTML comment tags.

<!--?php include("includes/get-graduates-main.inc"); ?-->

BTW I'm trying this because HannaCode doesn't seem to be supported by 2.5. Otherwise, I'd have a HannaCode in the text field.

Link to comment
Share on other sites

It's possible, only not recommended. Take a look at this thread https://processwire.com/talk/topic/3004-is-there-any-way-to-execute-php-loaded-from-textarea-fields/?p=29541

If you lose  the opening and closing PHP tags in your 'Inject Include' code, you can use php eval, http://php.net/manual/en/function.eval.php to execute the code in the template.

But you really should be using Hanna (which should work also in 2.5.5) or maybe http://modules.processwire.com/modules/markup-shortcodes/

  • Like 2
Link to comment
Share on other sites

Yep, Hanna - she is much safer.

If you want to make it less techy, you could create a drop down with preset values that are then written into the template with the logic:

If include value is "Graduate" include this file

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...