CubeCart allows you to add custom dynamic pages to the storefront — for example a wishlist, store news, or any feature not included in the core. This guide explains how CubeCart routes requests and where to add your custom code.
How CubeCart Page Routing Works
CubeCart uses a URL parameter _a to determine which page to display. For example:
-
?_a=product— loads the product detail page -
?_a=basket— loads the cart page -
?_a=news— would load a custom “news” page (if you create one)
With SEO URLs enabled, these are rewritten to clean paths automatically.
The Routing Process
-
index.phploads the main controller. - The controller initialises the CubeCart class and calls
loadPage(). -
loadPage()reads the_aparameter and checks for a matching handler. - If no built-in match is found, it looks for a custom class or hook to handle the request.
Method 1: Using a Plugin (Recommended)
This is the preferred approach as plugins are preserved during upgrades.
- Create a plugin following our hooks system guide.
- In your plugin, hook into
class.cubecart.construct. - Check the value of
$_GET['_a']to identify your custom page. - Assign your data to Smarty variables and load your custom template.
Example hook code:
if (isset($_GET['_a']) && $_GET['_a'] === 'news') {
// Fetch your data
$news_items = getNewsItems();
// Assign to template
$GLOBALS['smarty']->assign('NEWS_ITEMS', $news_items);
// Load your custom template
$GLOBALS['smarty']->assign('PAGE_CONTENT',
$GLOBALS['smarty']->fetch('templates/news.html'));
}
Place your custom template file (e.g. news.html) in your plugin’s templates directory or your skin’s templates directory.
Method 2: Using a Custom Class
CubeCart has an autoloader that automatically loads any class file in the classes/ directory matching the pattern *.class.php.
- Create a file named after your page, e.g.
classes/news.class.php. - Define your class with a method matching the
_avalue. - CubeCart will find and execute it when the matching URL is requested.
Note: This method places files in the core classes/ directory, which means they may be overwritten during upgrades. Method 1 (plugins) is preferred for this reason.
Adding a Template
Your custom page will need a Smarty template. Create an HTML file in your skin’s templates/ directory (e.g. skins/foundation/templates/news.html) and use Smarty syntax to display your data.
SEO URLs
Once your custom page works with ?_a=news, you can create a clean SEO URL for it in Admin > Settings > SEO.