You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OctoberCMS静态页面Snippets修改异常技术求助

Hey there, let's break down how to fix this weird issue where your plugin's Snippet works fine in Static Pages but breaks when you tweak settings like showTitle:

Troubleshooting Steps & Fixes

First, let's start with the most common culprits and work our way through:

1. Double-Check Snippet Property Registration in Plugin.php

Make sure your Snippet is correctly mapping the Text component's properties in the registerSnippets() method. If the property definitions don't match what's in your component, changing settings won't propagate properly.

Here's what a correct registration should look like:

public function registerSnippets()
{
    return [
        'YourPlugin\Components\Text' => [
            'name' => 'Text Content Snippet',
            'description' => 'Add configurable text content with title toggle',
            'properties' => [
                'contentID' => [
                    'title' => 'Content ID',
                    'description' => 'Select existing text content',
                    'type' => 'dropdown', // Match your selector type here
                    'required' => true
                ],
                'showTitle' => [
                    'title' => 'Show Title',
                    'description' => 'Toggle content title visibility',
                    'type' => 'checkbox',
                    'default' => false
                ]
            ]
        ]
    ];
}

Ensure the properties array exactly mirrors the properties defined in your Text.php component.

2. Verify Component Property Handling in Text.php

Your component needs to properly expose properties to both the backend form and frontend template. Check the defineProperties() method:

public function defineProperties()
{
    return [
        'contentID' => [
            'title' => 'Content ID',
            'description' => 'Select existing text content',
            'type' => 'dropdown',
            'required' => true
        ],
        'showTitle' => [
            'title' => 'Show Title',
            'description' => 'Show or hide the content title',
            'type' => 'checkbox',
            'default' => false
        ]
    ];
}

Also, in the onRun() method, make sure you're passing the updated property value to the template:

public function onRun()
{
    // Fetch your content model
    $content = \YourPlugin\Models\TextContent::find($this->property('contentID'));
    
    // Pass data to the template
    $this->page['content'] = $content;
    $this->page['showTitle'] = $this->property('showTitle'); // Critical: use the dynamic property value
}

3. Fix Template Logic in default.htm

If your template isn't using the dynamic showTitle value, changing the Snippet setting will do nothing. Double-check your component template:

{% if showTitle %}
    <h2 class="content-title">{{ content.title }}</h2>
{% endif %}
<div class="content-body">{{ content.body|raw }}</div>

Avoid hardcoding true/false here—always reference the variable passed from the component.

4. Clear October CMS Cache

October loves caching, and stale cache is a super common cause of "setting changes not taking effect" issues. Do these steps:

  • Go to Settings > System > Cache in the backend and click "Clear Cache"
  • Alternatively, run these commands in your project root:
    php artisan cache:clear
    php artisan october:up
    
  • Temporarily disable template cache by setting enableTemplateCache = false in config/cms.php to test if caching was the problem.

5. Check Static Pages Database Storage

If none of the above works, verify that Static Pages is actually saving your updated settings. Look at the static_pages_pages table in your database, find the page with your Snippet, and check the snippets column. You should see the updated showTitle value (either true or false) in the serialized array. If it's not updating, there might be a form field mismatch between your Snippet registration and the Static Pages form handler.


内容的提问来源于stack exchange,提问作者Takács Gábor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:20:35