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

如何默认用非p标签包裹apostrophe-rich-text值及实现固定样式可编辑h3

Apostrophe Rich-Text Component Customization Solutions

Hey there! Let's walk through solutions for your two Apostrophe CMS rich-text needs:

1. Using a Default Tag Other Than <p> for apostrophe-rich-text

To make the apostrophe-rich-text component wrap content in a tag other than <p> by default, use the defaultTag option in your singleton/area configuration. This tells the editor to use your specified tag as the base for all new content.

Example Configuration:

{{ apos.singleton(data.page, 'customContent', 'apostrophe-rich-text', {
  defaultTag: 'h3', // Swap this with your desired tag (h2, div, etc.)
  // Add other needed options like styles or toolbar settings here
}) }}

This ensures any new content added to the field starts wrapped in your chosen tag instead of the default <p>.

2. Building a Fixed-Style Editable <h3> (No Style Dropdown)

Your existing code is almost there! To remove the style dropdown and lock content to a fixed <h3> with your custom class, adjust the configuration like this:

Updated Code:

<div class="wrapper">
  {{ apos.singleton(data.widget, 'name', 'apostrophe-rich-text', {
    defaultTag: 'h3', // Forces the editor to use h3 as the base tag
    styles: [
      { 
        name: 'Title', 
        element: 'h3', 
        attributes: { class: 'profileTitle' } 
      }
    ],
    toolbar: [], // Hides the entire toolbar (including the style dropdown)
    controls: { movable: false } // Keeps the widget from being repositioned
  }) }}
</div>

Key Changes Explained:

  • defaultTag: 'h3': Ensures the editor always starts with an <h3> tag, so users can't switch to a different base tag accidentally.
  • toolbar: []: Removes the entire toolbar (including the "Styles" dropdown), eliminating any way for users to change the tag or style.
  • The styles array retains your custom class setup, so the rendered <h3> will always have the profileTitle class.
  • controls: { movable: false }: Keeps the widget fixed in place as you originally set.

Users can still edit the text content, but the <h3> tag and its styling will stay locked in place.


内容的提问来源于stack exchange,提问作者1cgonza

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 06:36:25