在CrafterCMS Studio中拖动字段

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

Dragging fields in CrafterCMS Studio

问题

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

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

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

以及相应的代码:

  1. export default async function TestPage() {
  2. const model = await getModel('/site/website/test/index.xml');
  3. return (
  4. <TestComponent model={model} />
  5. );
  6. }
  7. export default function TestComponent(props) {
  8. const { isAuthoring } = useCrafterAppContext();
  9. const { model } = props;
  10. return (
  11. <ExperienceBuilder path={model.craftercms.path} isAuthoring={isAuthoring}>
  12. <Model model={model} >
  13. <div className="space-y-4">
  14. <RenderField
  15. model={model}
  16. fieldId="title_s"
  17. className="text-xl text-gray-800"
  18. />
  19. <RenderField
  20. model={model}
  21. fieldId="text_t"
  22. className="text-xl text-gray-800"
  23. />
  24. </div>
  25. </Model>
  26. </ExperienceBuilder>
  27. );
  28. }

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

  1. <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:

  1. export default async function TestPage() {
  2. const model = await getModel(&#39;/site/website/test/index.xml&#39;);
  3. return (
  4. &lt;TestComponent model={model} /&gt;
  5. );
  6. }
  1. export default function TestComponent(props) {
  2. const { isAuthoring } = useCrafterAppContext();
  3. const { model } = props;
  4. return (
  5. &lt;ExperienceBuilder path={model.craftercms.path} isAuthoring={isAuthoring}&gt;
  6. &lt;Model model={model} &gt;
  7. &lt;div className=&quot;space-y-4&quot;&gt;
  8. &lt;RenderField
  9. model={model}
  10. fieldId=&quot;title_s&quot;
  11. className=&quot;text-xl text-gray-800&quot;
  12. /&gt;
  13. &lt;RenderField
  14. model={model}
  15. fieldId=&quot;text_t&quot;
  16. className=&quot;text-xl text-gray-800&quot;
  17. /&gt;
  18. &lt;/div&gt;
  19. &lt;/Model&gt;
  20. &lt;/ExperienceBuilder&gt;
  21. );
  22. }

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 ... />,然后您应该能够通过拖放、上下按钮上的上下文菜单或内容表单来重新排序。

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

  1. <RenderRepeat
  2. model={model}
  3. fieldId="yourRepeatGroupId_o"
  4. componentProps={{ className: "space-y-4" }}
  5. renderItem={(item, index) => (
  6. <RenderField
  7. model={model}
  8. fieldId="yourRepeatGroupId_o.title_s"
  9. index={index}
  10. className="text-xl text-gray-800"
  11. />
  12. )}
  13. />

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

英文:

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:

  1. &lt;RenderRepeat
  2. model={model}
  3. fieldId=&quot;yourRepeatGroupId_o&quot;
  4. componentProps={{ className: &quot;space-y-4&quot; }}
  5. renderItem={(item, index) =&gt; (
  6. &lt;RenderField
  7. model={model}
  8. fieldId=&quot;yourRepeatGroupId_o.title_s&quot;
  9. index={index}
  10. className=&quot;text-xl text-gray-800&quot;
  11. /&gt;
  12. )}
  13. /&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:

确定