Skip to content

Render templates without warnings when a site has no sections - #656

Merged
uldisrudzitis merged 1 commit into
masterfrom
fix-no-sections-warnings
Oct 8, 2026
Merged

uldisrudzitis merged 1 commit into
masterfrom
fix-no-sections-warnings

Conversation

@uldisrudzitis

@uldisrudzitis uldisrudzitis commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

On a site with no sections, every template showed PHP warnings:

Warning: Trying to access array offset on null in SectionTemplateRenderService.php on line 221
Warning: Trying to access array offset on null in SectionTemplateRenderService.php on line 262
Warning: Trying to access array offset on null in MessyTemplateRenderService.php on line 202
Warning: Trying to access array offset on null in MessyTemplateRenderService.php on line 282

The body and entries-list class builders read $currentSection['name'] even when there is no current section. They now add xContent-<name> and xSection-<name> only when a section exists, as the editor's SectionRenderService.getBodyClasses() already does. xSectionType-default is still added, so styles based on section type still apply. Pages that have a section get the same classes as before.

  • SectionTemplateRenderService: getBodyClasses() and getPageEntriesAttributes() (Default, White, Mashup)
  • MessyTemplateRenderService: getBodyClassList() and getPageEntriesClasses()

Testing

  • New tests/Feature/SectionTemplateRenderServiceTest.php covers both services with no sections and with a section. Before the fix it fails with the same warning; it passes now.
  • Not yet checked on a real site with no sections in the browser.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Pages without a current section no longer receive section-name styling classes.
    • Section-type and entry-list classes continue to appear as expected, and pages with a current section retain their section-name classes.

The body and entries-list class builders read the current section's name
unconditionally, so a site with no sections raised "Trying to access array
offset on null" on every template. Add the section-name classes only when
a current section exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b547bab8-6b5c-43b5-afed-4d43a38fa1c7
📥 Commits

Reviewing files that changed from the base of the PR and between d075ce3 and 66ae74f.

📒 Files selected for processing (3)
  • _api_app/app/Sites/Sections/MessyTemplateRenderService.php
  • _api_app/app/Sites/Sections/SectionTemplateRenderService.php
  • _api_app/tests/Feature/SectionTemplateRenderServiceTest.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Both template render services now add section-name classes only when a current section exists. Tests cover rendered classes for sites with no sections and with an about section.

Changes

Section class rendering

Layer / File(s) Summary
Conditional section class output
_api_app/app/Sites/Sections/MessyTemplateRenderService.php, _api_app/app/Sites/Sections/SectionTemplateRenderService.php, _api_app/tests/Feature/SectionTemplateRenderServiceTest.php
Both services omit section-name classes when no current section exists. The section-type and entries-list classes remain. Tests check output with and without an about section.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 66ae7

Pages without a current section omit only section-name classes, while retaining the default section type and entry-list classes. No actionable merge risk is established.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing template-rendering warnings when a site has no sections.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@uldisrudzitis
uldisrudzitis merged commit 71c2e8b into master Oct 8, 2026
7 checks passed
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.

1 participant