Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 16, 2025

Fix CarouselSlidePlugin and TabItemPlugin template retrieval issue

Problem

In version 2.0.0, CarouselSlidePlugin and TabItemPlugin stopped respecting their parent plugin's template setting when multiple templates are configured. This caused child plugins to always render using the first (default) template, regardless of which template was selected on the parent carousel or tab container.

For example, with the following configuration:

DJANGOCMS_FRONTEND_CAROUSEL_TEMPLATES = (
    ("default", "Default"),
    ("fancy", "Fancy"),
    ("minimal", "Minimal"),
)

Even when a Carousel is explicitly set to use the "fancy" template, all its slides would incorrectly render using the "default" template.

Root Cause

The issue was in the get_render_template() methods of both plugins. They were using:

instance.parent or instance

This returns instance.parent which is a CMSPlugin instance (the base model). The CMSPlugin model doesn't have a template field - only the actual plugin models (like Carousel or Tab) have this field in their configuration. Without access to the template field, get_plugin_template() falls back to first_choice(templates), always returning the first available template.

Solution

Changed the code to properly retrieve the actual plugin instance:

instance.parent.get_plugin_instance()[0] if instance.parent else instance

The get_plugin_instance() method returns a tuple of (plugin_instance, plugin_class). Using [0] extracts the actual typed plugin instance (e.g., Carousel) which has the template field, allowing the correct template to be used.

Changes

  • Fixed CarouselSlidePlugin.get_render_template() in djangocms_frontend/contrib/carousel/cms_plugins.py
  • Fixed TabItemPlugin.get_render_template() in djangocms_frontend/contrib/tabs/cms_plugins.py
  • Added test test_carousel_slide_inherits_parent_template() to verify carousel template inheritance
  • Added test test_tab_item_inherits_parent_template() to verify tab template inheritance
  • Fixed flake8 compliance issues (removed unused import, fixed whitespace)

Notes

This fix aligns with the pattern already used in the framework render mixins (carousel/frameworks/bootstrap5.py and tabs/frameworks/bootstrap5.py) which correctly use instance.parent.get_plugin_instance()[0] to access the parent plugin.

The change is backward compatible - if no parent exists, it falls back to using the instance itself.

Fixes #313

Original prompt

This section details on the original issue you should resolve

<issue_title>CarouselSlidePlugin refers to wrong "slide.html" Template</issue_title>
<issue_description>With 2.0.0 and and changes in regards to #220, the following line breaks the retrieval of the correct slide.html Template for the CarouselSlidePlugin:

https://github.com/django-cms/djangocms-frontend/blame/2.0.0/djangocms_frontend/contrib/carousel/cms_plugins.py#L89

instance.parent seems to refer to the CMSPlugin model which does not have a "template" field (should refer to CarouselPlugin).

Therefore get_plugin_template() falls back to first_choice() and retrieves the wrong (first) slide.html, if you have multiple Carousel Templates defined in DJANGOCMS_FRONTEND_CAROUSEL_TEMPLATES.

Downgrading to 1.3.5 fixes the behaviour.

(django-cms==4.1.9)</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #313


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: fsbraun <16904477+fsbraun@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CarouselSlidePlugin template retrieval issue Fix CarouselSlidePlugin and TabItemPlugin template retrieval to respect parent template setting Oct 16, 2025
Copilot AI requested a review from fsbraun October 16, 2025 08:42
@fsbraun fsbraun changed the title Fix CarouselSlidePlugin and TabItemPlugin template retrieval to respect parent template setting fix: CarouselSlidePlugin and TabItemPlugin template retrieval to respect parent template setting Oct 16, 2025
@fsbraun
Copy link
Member

fsbraun commented Oct 16, 2025

@copilot MAke changes flake8 compliant

Co-authored-by: fsbraun <16904477+fsbraun@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 16, 2025

@copilot MAke changes flake8 compliant

Fixed flake8 compliance issues:

  • Removed unused import of CAROUSEL_TEMPLATE_CHOICES
  • Removed trailing whitespace from blank lines in test files

All modified files now pass flake8 validation with the project's configuration (max-line-length=120). Commit: (hash will be in next push)

Copilot AI requested a review from fsbraun October 16, 2025 10:05
@codecov
Copy link

codecov bot commented Oct 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.13%. Comparing base (9844b4c) to head (d97e331).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #314   +/-   ##
=======================================
  Coverage   89.13%   89.13%           
=======================================
  Files         124      124           
  Lines        3387     3387           
  Branches      288      288           
=======================================
  Hits         3019     3019           
  Misses        252      252           
  Partials      116      116           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fsbraun fsbraun marked this pull request as ready for review October 16, 2025 10:22
@fsbraun fsbraun merged commit d2de207 into main Oct 16, 2025
31 checks passed
@fsbraun fsbraun deleted the copilot/fix-carousel-slide-template-retrieval branch November 19, 2025 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CarouselSlidePlugin refers to wrong "slide.html" Template

2 participants