在CrafterCMS Studio中拖动字段

huangapple go评论46阅读模式
英文:

Dragging fields in CrafterCMS Studio

问题

我目前正在自学如何使用一个无头 CMS(CrafterCMS)与 Next.js。

我在 CrafterCMS studio 中有以下简单的内容类型(只有标题和文本):

<img src="https://i.stack.imgur.com/9V1uJ.png" width="350" height="250">

以及相应的代码:

export default async function TestPage() {
    const model = await getModel('/site/website/test/index.xml');
    return (
        <TestComponent model={model} />
    );
}

export default function TestComponent(props) {
    const { isAuthoring } = useCrafterAppContext();
    const { model } = props;

    return (
        <ExperienceBuilder path={model.craftercms.path} isAuthoring={isAuthoring}>
            <Model model={model} >
                <div className="space-y-4">
                    <RenderField
                        model={model}
                        fieldId="title_s"
                        className="text-xl text-gray-800"
                    />

                    <RenderField
                        model={model}
                        fieldId="text_t"
                        className="text-xl text-gray-800"
                    />
                </div>
            </Model>
        </ExperienceBuilder>
    );
}

是否可以使用 Studio 的功能来拖动并更改我的两个字段的位置?例如,我想要将文本拖到第一个元素的位置。看起来我只能更改内容,拖动不可用:

<img src="https://i.stack.imgur.com/u8Y9U.png" width="350" height="250">
英文:

I'm currently teaching myself how to use a headless CMS (CrafterCMS) with Next.js.

I have the following simple content type in CrafterCMS studio (just a title and a text):

<img src="https://i.stack.imgur.com/9V1uJ.png" width="350" height="250">

And the respective code:

export default async function TestPage() {
    const model = await getModel(&#39;/site/website/test/index.xml&#39;);
    return (
        &lt;TestComponent model={model} /&gt;
    );
}
export default function TestComponent(props) {
    const { isAuthoring } = useCrafterAppContext();
    const { model } = props;

    return (
        &lt;ExperienceBuilder path={model.craftercms.path} isAuthoring={isAuthoring}&gt;
            &lt;Model model={model} &gt;
                &lt;div className=&quot;space-y-4&quot;&gt;
                    &lt;RenderField
                        model={model}
                        fieldId=&quot;title_s&quot;
                        className=&quot;text-xl text-gray-800&quot;
                    /&gt;

                    &lt;RenderField
                        model={model}
                        fieldId=&quot;text_t&quot;
                        className=&quot;text-xl text-gray-800&quot;
                    /&gt;
                &lt;/div&gt;
            &lt;/Model&gt;
        &lt;/ExperienceBuilder&gt;
    );
}

Is it possible to use Studio functionality to drag and change the positions of my two fields? For example I want to drag the text to be the first element. It seems that i only have the option to change the content, dragging is not available:

<img src="https://i.stack.imgur.com/u8Y9U.png" width="350" height="250">

答案1

得分: 2

在CrafterCMS上,您可以主要拖放三种内容:

  • 重复组项
  • 使用“组件”数据源的项目选择器控件中的组件项引用
  • 媒体项目到媒体控件(图像或视频)

实现您所描述的最简单方法是将您想要通过拖放重新排序的字段放在重复组内(即创建一个重复组并将“标题”输入控件放在其中;只有一个,丢弃其他的)。完成后,您需要更新您的TestComponent代码以使用<RenderRepeat ... />,然后您应该能够通过拖放、上下按钮上的上下文菜单或内容表单来重新排序。

渲染带有标题字段的重复部分,大致如下:

<RenderRepeat
  model={model}
  fieldId="yourRepeatGroupId_o"
  componentProps={{ className: "space-y-4" }}
  renderItem={(item, index) => (
    <RenderField
      model={model}
      fieldId="yourRepeatGroupId_o.title_s"
      index={index}
      className="text-xl text-gray-800"
    />
  )}
/>

正如我提到的,您可以通过组件(项目选择器控件、组件数据源)来实现,但对于这种情况,重复组是最简单的方法;特别是为了开始学习。

英文:

On CrafterCMS, you can drag & drop mainly 3 things:

  • Repeating group items
  • Component item references from an Item Selector control with a "Components" datasource
  • Media items into a media control (image or video)

The simplest way of achieving what you describe, would be to change your model to wrap with a repeat group the fields you want to reorder via drag & drop (i.e. create a repeat group and add the "title" input control inside of it; only 1, discard the other). Once you've done that, you'll need to update your TestComponent code to use &lt;RenderRepeat ... /&gt; and you should be able to reorder via drag & drop, via the contextual menu up/down buttons, or via the content form.

The rendering of the repeat with your title field, would roughly look something like this:

&lt;RenderRepeat
  model={model}
  fieldId=&quot;yourRepeatGroupId_o&quot;
  componentProps={{ className: &quot;space-y-4&quot; }}
  renderItem={(item, index) =&gt; (
    &lt;RenderField
      model={model}
      fieldId=&quot;yourRepeatGroupId_o.title_s&quot;
      index={index}
      className=&quot;text-xl text-gray-800&quot;
    /&gt;
  )}
/&gt;

As I mentioned, you could achieve it via components (Item selector control, Components datasource), but the repeat group is simplest for this case; specially to get started and learn.

huangapple
  • 本文由 发表于 2023年6月2日 04:08:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76385362.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定