Creating a page?

As you might expect that will not work. ;)

Ok, into the the Template HTML-field you write:

HTML:
<div class="baseHtml messageText">

{xen:raw $myContent}

</div>


You have to set a PHP callback class and method

class-name: XenForo_Pages_Test

method-name: includeFile

When naming the class you should keep the xenforo folder structure in mind.

Now you have to create a php-file <xenforo>/library/XenForo/Pages/Test.php. The sub-folder Pages does not exists by default, so you have to create it first. The file/path and the clase-name must match or you will end up in an error.

The php-file content:
PHP:
<?php
class XenForo_Pages_Test
{
     public static function includeFile(XenForo_ControllerPublic_Abstract  $controller, XenForo_ControllerResponse_Abstract &$response)
    {
        ob_start();
        require('/path/to/your/html/file.html');
        $myContent = ob_get_contents();
        ob_end_clean();

        $params = array(
            'myContent'  => $myContent
        );

        $response->params = array_merge(
            $response->params,
            $params
        );
    }
}
That example is quite simple, you can easily assign more variables to the $params-array or include php-files with even more vars. :-D

Edit: Added <?php to the code example.

I'm trying to include a single php file(page-pickup-lines.php) into a forum page. I tried following your method, but get an error when I try to view the for page:
Fatal error: XenForo_Pages_PickupLines::includeFile() [function.require]: Failed opening required '/home/xarcell/public_html/xxxxxx.com/page-pickup-lines.php' (include_path='/home/xarcell/public_html/xxxxxx.com/library:.') in /home/xarcell/public_html/xxxxxx.com/library/XenForo/Pages/PickupLines.php on line 19

Here's what I did...

Created PickupLines.php and uploaded to library/Xenforo/Pages with the following content:
PHP:
<?php
class XenForo_Pages_PickupLines
{
     public static function includeFile(XenForo_ControllerPublic_Abstract  $controller, XenForo_ControllerResponse_Abstract &$response)
    {
        ob_start();
        require('/home/xarcell/public_html/inspireromance.com/page-pickup-lines.php');
        $pickupLines = ob_get_contents();
        ob_end_clean();

        $params = array(
            'pickupLines'  => $pickupLines
        );

        $response->params = array_merge(
            $response->params,
            $params
        );
    }
}

Then I created a forum page with this as the HTML:
Code:
<div class="baseHtml messageText">

{xen:raw $pickupLines}

</div>
Callback: "XenForo_Pages_PickupLines :: includeFile"

What did I do wrong?

My php file that I'm trying to include contains this:
Code:
<?php

echo '<div>hello world</div>';

?>
 
Now I have another problem. I am unable to apply any classes or add CSS to the php file. What is the proper way of doing that?

CSS classes are referenced in your HTML code. For example:

PHP:
<?php

echo '<div class="secondaryContent">hello world</div>';

?>

You can make use of xenForo CSS classes in your HTML because it will be output within a xenForo page node.
 
I am getting this when submitting a form, it seems to pull the php fine until I submit the form thats in the included file:

Security error occurred. Please press back, refresh the page, and try again.

Any ideas on how I could fix it? :)

Thanks
 
Could you tell me where that would go please?

I tried this but it didnt work:

Code:
    <form method="post" name="_xfToken" value="{$visitor.csrf_token_page}">

and I then removed that and added this below the submit input:

Code:
    <input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />

Not really sure where these should be or if theyre correct.
 
It should be
Code:
<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
and doesn't care where you place it, it just have to be in the form;)
for example before the closing tag


<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
</form>
 
It should be
Code:
<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
and doesn't care where you place it, it just have to be in the form;)
for example before the closing tag


<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
</form>

Thanks, now I get this on submit:

A server error occurred. Please try again later.

Any ideas how to fix that? :)
 
Here's what I did...

Created PickupLines.php and uploaded to library/Xenforo/Pages with the following content:
PHP:
<?php
class XenForo_Pages_PickupLines
{
    public static function includeFile(XenForo_ControllerPublic_Abstract  $controller, XenForo_ControllerResponse_Abstract &$response)
    {
        ob_start();
        include('/home/xarcell/public_html/inspireromance.com/page-pickup-lines.php');
        $pickupLines = ob_get_contents();
        ob_end_clean();

        $params = array(
            'pickupLines'  => $pickupLines
        );

        $response->params = array_merge(
            $response->params,
            $params
        );
    }
}

Then I created a forum page with this as the HTML:
Code:
<div class="baseHtml messageText">

{xen:raw $pickupLines}

</div>
Callback: "XenForo_Pages_PickupLines :: includeFile"

My php file that I'm trying to include contains this:
Code:
<?php

echo '<div>hello world</div>';

?>

So what if I want to include $pickupLines in an other template? How would I approach this? simply placing: {xen:raw $pickupLines} somewhere doesnt seem to do the trick....
 
So what if I want to include $pickupLines in an other template? How would I approach this? simply placing: {xen:raw $pickupLines} somewhere doesnt seem to do the trick....
Yes, i'd like to do the same, include it into templates but adding {xen:raw $pickupLines} is not working. Please help.
 
A little old post I know, but everything I search for including a PHP file in xenforo is outdated, if that matters or not.
Anyways, I've followed the instructions here and after some trial and error I finally got the page showing without errors (mostly due to file paths that I overlooked), but, it's not showing the contents of the php file it's pointing to. Which is located at /donate/donate.php.


The main content PHP file is a donation script that requires other PHP files for mysql connection and config.
The include file path is the absolute path to the donate.php so I know it's pointing to it.
Callback is XenForo_Pages_Test :: includeFile

All that's showing is the title "Donations" then the footer.

I'm tired and probably overlooking something, but thought I'd post and see if someone can help me somehow by tomorrow.
 
Top Bottom