In Concrete5 we can place php files in the tools directory, which we can run with ajax. This means we can load that php file without refreshing the page on page load, or when we click a link or button etc.

First of all we add our tools file under /application/tools.  For testing we can just add a log entry:

defined('C5_EXECUTE') or die("Access Denied.");

Log::AddEntry('Hello World');

Save this as test_tool.php.

Calling our tools file via ajax:

In the page or file where we want to call the tools file, we need to add the path to the tool at the top:

$tools_url = Loader::helper('concrete/urls')->getToolsURL('test_tool');

Note how you don't add .php to the end of the file and you don't put the whole path - Concrete5 knows what to do with just the above.

Then in our file we can add the ajax like so:

            url: "<?php echo $tools_url ?>", 
            context: document.body            
        }).done(function() {
            console.log('ajax complete');

Note, this will trigger the tools file on page load.

All you then need to do is refresh the page and check the logs and you should see your message from your tools file!

Who are we?

We are a digital agency specialising in Web Design, Development, Concrete5 and digital marketing, based in London & West Sussex.

We make digital simple. Our purpose is to simplify your frustrations in digital and solve the challenges you face to help make you more money and progressively grow your business or organisation.

Tell me more

Keep up to date

Call us