Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+5 votes
1.5k views
in Q2A Core by
edited
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
by

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.

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

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
by

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";
        }
    }

...