Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Would it be possible to allow for PHP in addition to HTML in the custom layout pages?

+5 votes
926 views
asked Dec 13, 2010 in Q2A Core by anonymous
edited Dec 13, 2010
Would it be possible to allow for PHP in addition to HTML in the custom layout pages?  This may seem a little odd, but there are small scripts/unique routines that I may like to add to a page unrelated to the QA script itself.

 

Thanks

3 Answers

+3 votes
answered Dec 14, 2010 by gidgreen

It's an interesting idea, but for now I suggest you do this using an advanced theme, which allows you to run any PHP code at any point on the page.

Or you can modify qa-page.php wherever it calls output_raw(...) in the theme object. You can make use of PHP's eval(...) function to run the PHP which was stored in the appropriate option setting.

commented Dec 17, 2010 by Scott
You could also create your own page plugin, right?
commented Dec 17, 2010 by gidgreen
Page modules/plugins are for creating an entirely new type of page in Q2A, rather than changing something that applies to all pages.
commented Dec 17, 2010 by Scott
Yes you're right, I didn't read the question properly :/
+2 votes
answered Sep 26, 2012 by j0nnye

The way I got around it was by loading the php into a div inside the custom html  with jquery's .load() ... for example...

<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
</head>

<script>
 $(document).ready(function() {
 
   $("#test_container").load("location/to/yourphppage.php");
 
});
</script>
 

<div id="test_container"></div>

 

...it worked fine for me

+1 vote
answered Mar 23, 2017 by yoann

This is an update of the answer provided by gidgreen, for q2a 1.7.4.

using an advanced theme, you can override output_raw() this way :

    public function output_raw($html)
    {
        if (strlen($html)) {
            $html = eval('?>'.$html.'<?php ');
            echo str_repeat("\t", max(0, $this->indent)).$html."\n";
        }
    }

...