Override template Content Cart
Content Cart 4.0 Template Overrides
Content Cart 4.0 supports full template overrides via the standard Joomla templating system
Important changes in version 4.0
In version 4.0, the template structure has been completely redesigned:
- The plugin now uses Joomla Layouts instead of regular templates
- Layouts provide better portability and code reusability
- Improved template security (extract() function removed)
- Support for modern Joomla 5/6 architecture
Module Template Override
"Content Cart" Module
Standard method (via Joomla admin panel)
- Go to: System -> Site Templates -> Details and Files
- Select your active template
- Click "Create Overrides"
- Find and select mod_contentcart
- The system will automatically create the override
Manual method
Copy the module template file from:
To your template folder:
What's new in 4.0
- Dynamic updates via JavaScript
- Display of product list
- localStorage support
- AJAX interaction
Tip: Do not remove data-attributes and classes for JS
Plugin Template Overrides (Layouts)
New structure in version 4.0 - Joomla Layouts
The plugin uses the Joomla Layouts system for all templates. This allows:
- Overriding templates via the standard Joomla system
- Using overrides in multiple templates simultaneously
- Receiving security updates without losing customization
Step-by-step override instructions
Step 1 Create folder structure
Create a folder for layout overrides in your template:
Note: the path includes layouts, not just html
Step 2 Copy layout files
Copy the necessary files from the plugin's layouts folder:
To the created override folder:
| File | Purpose | Changes in 4.0 |
|---|---|---|
cart.php |
Shopping cart page with order form | Updated |
default.php |
"Add to Cart" button in article | Updated |
mail.php |
Email template for order confirmation | New layout |
Advantage of Layouts
The Layouts system automatically searches for overrides in the correct order:
- In your template:
/templates/your_template/html/layouts/plg_content_contentcart/ - In the plugin:
/plugins/content/contentcart/layouts/
Step 3 Edit templates
Now you can edit the copied files to suit your needs.
Critically important to preserve:
- Data-attributes - used by JavaScript for cart functionality
- Element IDs - necessary for AJAX updates
- Classes for JS - for example,
contentcart-add-btn - CSRF-tokens - critically important for security
- $displayData variables - passed from the plugin
Detailed layout description
cart.php - Shopping Cart Page
Purpose: Main template for the shopping cart page with order form
Key elements:
- Table of items in the cart
- Fields for changing item quantities
- Buttons for removing items
- Form with customer data (name, email, phone, comment)
- Calculation of total order amount
- Order submission button
- CSRF-token for security
New in version 4.0:
- Working with localStorage via JavaScript
- Dynamic updates via AJAX
- Server-side validation
- Improved security (CSRF protection)
Available variables
$displayData['row']- article$displayData['params']- parameters$displayData['cart_url']- cart URL$displayData['session']- session
default.php - "Add to Cart" Button
Purpose: Button for adding an item to the cart on the article page
Key elements:
- "Add to Cart" button
- Display of item price
- Data-attributes for JavaScript
- CSRF-token
New in version 4.0:
- Smart button (changes state after adding)
- Price is taken only from the server (security)
- AJAX-add support
- Automatic cart module update
Available variables
$displayData['row']- article$displayData['params']- parameters$displayData['link']- link$displayData['cart_url']- cart URL
mail.php - Email Notification
Purpose: Email template with order information
Key elements:
- Customer information (name, email, phone)
- List of ordered items
- Prices and quantities of items
- Total order amount
- Customer comment (if any)
Critical changes in version 4.0:
- extract() function removed - was a security threat
- Now it's a Joomla Layout instead of a regular template
- Data validation added
- Improved email HTML structure
Important!
Do not use extract() in overrides. It's insecure!
Access variables via $displayData.
Final Folder Structure
Module Overrides
Plugin Overrides (Layouts)
Migration of Overrides from Version 2.0
If you are upgrading from version 2.0
In version 2.0, plugin templates were located in the tmpl/ folder and overridden in:
In version 4.0, you need to move them to:
Step-by-step migration:
- Create a new folder:
/templates/your_template/html/layouts/plg_content_contentcart/ - Copy your overridden files from the old folder to the new one
- Update the file code according to new security requirements (remove extract(), update CSRF-tokens)
- Check the functionality of all templates
- Delete the old folder after successful testing
Useful Tips
Recommended
- Make backups before making changes
- Test on a local server
- Preserve all data-attributes
- Check JavaScript functionality after changes
- Use comments in your code
- Update overrides after plugin updates
- Use variables via
$displayData
Not Recommended
- Editing original plugin files
- Removing CSRF-tokens
- Using extract() in templates
- Changing IDs and classes for JavaScript
- Removing data-attributes
- Forgetting about security
- Using the old path from version 2.0