Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for using collection_item in a sample/preview #100

Open
julianrubisch opened this issue Dec 16, 2024 · 3 comments
Open

Example for using collection_item in a sample/preview #100

julianrubisch opened this issue Dec 16, 2024 · 3 comments
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@julianrubisch
Copy link

Sorry for posting this here in the issue tracker, but I haven't found a link to a discussion board or similar...

I'm setting up a "news preview" in my app using collection_item in my app and it works like a charm 🪄

BUT: I can't figure out how to show them in an admin preview using the sample block. Here's what I've got:

name: "three columns with images"

category: blog

settings:
- label: "Title"
  id: title
  type: text
  default: Headline
- label: "Overview link"
  id: overview_link
  type: link
  with_text: true
  default: { text: "Link", href: "#" }

blocks:
- name: "Item"
  type: item
  limit: 3
  settings:
  - label: "News Item"
    id: news_item
    type: collection_item
    collection_id: news_items

blocks_label: "Top 3 News Items"

sample:
  settings:
    title: Aktuelle News
    overview_link: { text: "Link", href: "#" }
  blocks:
  - type: item
    settings: ???

This is probably hard to generalize, if it works at all, but one could potentially link to a test fixture or something?

@did did added documentation Improvements or additions to documentation question Further information is requested labels Dec 16, 2024
@did
Copy link
Contributor

did commented Dec 16, 2024

👋 @julianrubisch, the documentation is incomplete indeed and I've to update it.

In the meantime, you could use any as the id of the collection item. Something like this?

sample:
  settings:
    title: Aktuelle News
    overview_link: { text: "Link", href: "#" }
  blocks:
  - type: item
    settings:
       news_item: 
           id: any

@julianrubisch
Copy link
Author

Sorry to revisit this so late, but it seems I fail to understand what any does in this context. I've got a pretty simple section here:

settings:
- label: "Title"
  id: title
  type: text
  default: "What do you think?"
- label: "Survey question"
  id: survey_question
  type: collection_item
  collection_id: survey_questions
  default: any

with the following template:

  <%= maglev_section.wrapper_tag.div class: "bg-secondary-700 py-6 md:py-12 px-4 md:px-6" do %>

    <%= maglev_section.setting_tag :title %>

    <% item = maglev_section.settings.survey_question.item %>
    <%= render partial: item.to_partial_path, locals: { survey_question: item } %>
  <% end %>

But this sample section doesn't render anything:

sample:
  settings:
    title: "Was meinst du?"
    survey_question:
      id: any

Image

Note that I've added seed data that could be used here, but I just don't understand how? What am I missing?

@julianrubisch
Copy link
Author

A small addendum that maybe adds more context: It does work when I actually set the item in the Maglev Page Editor somewhere. 🤯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants