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

OctoberCMS Static Page插件自定义字段获取全站页面URL及报错咨询

Fixing the Static Pages Custom Field Page Selection Issue in OctoberCMS

Got it, let's tackle this OctoberCMS Static Pages plugin issue you're facing. That get_class() expects parameter 1 to be object, array given error pops up because the dropdown variable field isn't receiving the proper data format when used outside a Repeater. The Repeater works because its context automatically handles the data structure, but standalone needs a bit of tweaking. Here are a few user-friendly solutions to let your clients easily select pages:

Option 1: Use the Official Page Picker (Most User-Friendly)

If your Static Pages plugin version supports it, skip the dropdown entirely and use the built-in page field type. This is designed specifically for selecting pages, and it renders an intuitive searchable interface that your clients will love:

{variable name="selected_page" label="Choose a Page" type="page"}{/variable}

No extra code needed—this field lets users browse, search, and select any page in your system with zero hassle.

Option 2: Fix the Dropdown Field with Custom Data Source

If you prefer using a dropdown, you just need to explicitly pass it the right page data in a format it understands. Here's how:

  1. Go to your Static Page's Code tab and add this PHP snippet to fetch all pages as a key-value array:
    function onInit() {
        // Grab all static pages, format them for dropdown (ID as key, title as label)
        $this['pageOptions'] = \RainLab\Pages\Models\Page::all()->pluck('title', 'id')->toArray();
    }
    
  2. Update your custom field to use this prepped data source:
    {variable name="selected_page" label="Choose a Page" type="dropdown" options="{{ pageOptions }}"}{/variable}
    

Now the dropdown will load all page titles, and selecting one will store the corresponding page ID for you to use in your template.

Option 3: Stick with the Repeater Workaround (Quick Fix)

Since you already have a working Repeater-based solution, you can repurpose it for single-page selection by limiting the Repeater to one entry:

{repeater name="page_selector" label="Select a Page" prompt="Add Page" maxItems="1"}
    {variable name="page" label="Page" type="dropdown"}{/variable}
{/repeater}

In your template, just pull the first (and only) entry like this:

{{ page_selector[0].page }}

It's a bit of a hack, but it gets the job done quickly if you don't want to mess with new fields or code.

I'd recommend Option 1 first—it's the most polished and user-friendly for your clients.

内容的提问来源于stack exchange,提问作者Panagiotis Koursaris

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 03:35:00