This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

In this example we will be checking if the requested path is a specific package tools file.

The Request Library is extremely powerful, it allows concrete5 to see the path requested and to pull the relevant data from the database.

First we are going to get the current request:

$req = Request::get();

That will parse 1 of several server vars to see what the path is.

Now that we have a request object, we can check if it is a tool:

if($req->getIncludeType() == 'PACKAGE_TOOL') {
    //its a package tool!

that will check if the current request is a package tool. You can of course remove one of them.

Now we are going to get the tool's package handle:

$req->getPackageHandle() == 'my_pkg'

we can just add that to the if statement before

if($req->getIncludeType() == 'PACKAGE_TOOL' && $req->getPackageHandle() == 'my_pkg') {
    //its a my_pkg tool!

and finally we will get the actual tool (this can be a path if its a subdir)

$req->getFilename() == 'my_tool.php'

it will always end in .php we can add that to the if statement aswell.

For more generic parsing of paths (for any path) you can do something like the following:

    $req = Request::get();
    $path = $req->getRequestPath();//the path will be like cat1/sub1/subsub/page
    $exploded = explode('/', $path);
    if($exploded[0] == 'cat1' && $exploded[1] == 'sub1' && $exploded[2] == 'subsub' && $exploded[3] == 'page') {
        return true; //that is the requested page!
    return false;

There are several other methods in the request library that are extremely helpful. It is located in /concrete/libraries/request.php

Loading Conversation