Reference Specific Part in Template?

I’m using the One-Pager guide to implement Parts in a layout. I’m using the following code, which is working great:

      <?php foreach ($page->children() as $part) : ?>
        
          <?php snippet($part->intendedTemplate(), compact('part')) ?>
        
      <?php endforeach ?>

Is it possible to pull out only one specific part, and -then- have a separate loop that grabs all the other parts?

Put another way, I’d like to exclude one part from the above code so it spits out all the parts except one, and I want to display the other part by itself somewhere else. Not sure if that makes sense. Anyone know if it’s possible?

Sure, you can do that, for example using first(), last() or nth() you can get them by their position in the collection. Or you can filter them by some sort of criteria, depends on your use case.

Let’s assume you wanted to get the first element and then there rest:

$firstPart = $page->children()->first();
$rest = $page->children()->not(firstPart);

Then you can loop through the rest as before and for the first one you just call the snippet without a loop.

1 Like

Actually I think I have a better question -> Is it possible to use a “Parts” section in a blueprint for a page (so I can add sub-content to it) and have normal fields on the page too?

That would give me the same result, and potentially in an easier way…

Thank you!

Yes, of course.

1 Like

I’m breaking something with that approach:

sections:
  fields:
    projectCategories:
      label: What categories did this project fall into?
      type: structure
      max: 3
      fields:
        category:
          label: Category (e.g. Strategy, Design or Development)
          type: text
    projectSummary:
      type: text
      label: The Perfect Summary
  parts:
    headline: Parts
    type: pages
    empty: Add at least a project intro you noob.
    status: all
    info: "{{ project.intendedTemplate }}"
    image: false
    templates:
      - project-intro
      - project-summary
      - project-screenshot
      - project-text-row
      - project-image-and-text
      - project-left-image-and-text
      - project-quote

For example:

title: My blueprint

sections:
  myFieldsSection:
    type: fields
    fields:
      # your fields here
  myParts:
    type: pages
    # section for your subpages that make up the sections

You can, of course, use columns or tabs to create a nice layout for this stuff.

1 Like

The name and type for the first section is missing:

sections:
  nameOfSection:
    type: fields
    fields:
      projectCategories:
        label: What categories did this project fall into?
        type: structure
        max: 3
        fields:
          category:
            label: Category (e.g. Strategy, Design or Development)
            type: text
      projectSummary:
        type: text
        label: The Perfect Summary
  parts:
    headline: Parts
    type: pages
    empty: Add at least a project intro you noob. # not nice
    status: all
    info: "{{ project.intendedTemplate }}"
    image: false
    templates:
      - project-intro
      - project-summary
      - project-screenshot
      - project-text-row
      - project-image-and-text
      - project-left-image-and-text
      - project-quote
1 Like

I tried to click the Heart icon 1,000,000,000 times but my browser crashed and my mouse caught fire.

I’m still wrapping my brain around the blueprint formatting - every time I’m introduced to something reserved like “parts” where the nesting is different, it throws me. Thank you so much for your patience.

Should I send you a new one :wink:?

I have a backup. :laughing: