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)

  1. Go to: System -> Site Templates -> Details and Files
  2. Select your active template
  3. Click "Create Overrides"
  4. Find and select mod_contentcart
  5. The system will automatically create the override

Manual method

Copy the module template file from:

<code>/modules/mod_contentcart/tmpl/default.php</code>

To your template folder:

<code>/templates/your_template/html/mod_contentcart/default.php</code>

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:

<code>/templates/your_template/html/layouts/plg_content_contentcart/</code>

Note: the path includes layouts, not just html

Step 2 Copy layout files

Copy the necessary files from the plugin's layouts folder:

<code>/plugins/content/contentcart/layouts/</code>

To the created override folder:

<code>/templates/your_template/html/layouts/plg_content_contentcart/</code>
FilePurposeChanges 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:

  1. In your template: /templates/your_template/html/layouts/plg_content_contentcart/
  2. 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

layouts/cart.php

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
layouts/default.php

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
layouts/mail.php

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

<code>/templates/your_template/
└── html/
    └── mod_contentcart/
        └── default.php</code>

Standard Joomla module override

Plugin Overrides (Layouts)

<code>/templates/your_template/
└── html/
    └── layouts/
        └── plg_content_contentcart/
            ├── cart.php
            ├── default.php
            └── mail.php</code>

Override via Joomla Layouts system

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:

<code>/templates/your_template/html/plg_content_contentcart/</code>

In version 4.0, you need to move them to:

<code>/templates/your_template/html/layouts/plg_content_contentcart/</code>
Step-by-step migration:
  1. Create a new folder: /templates/your_template/html/layouts/plg_content_contentcart/
  2. Copy your overridden files from the old folder to the new one
  3. Update the file code according to new security requirements (remove extract(), update CSRF-tokens)
  4. Check the functionality of all templates
  5. 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

email: This email address is being protected from spambots. You need JavaScript enabled to view it.

© 2010- JoomLine

The Joomla!® name is used under a limited license from Open Source Matters in the United States and other countries. joomline.org is not affiliated with or endorsed by Open Source Matters or the Joomla! Project.