Forum

Thread tagged as: Question

How to use two seperate blocks in one region

I'm currently providing the user the option to create for a cv and an image:

2010    did this             |       
2011    did that             |  IMAGE GOES
2012    did another thingy   |     HERE
2015    still rocking        |

Now I'd like to provide the user with anther option to add multiple exhibitions below:

2010    did this             |       
2011    did that             |  IMAGE GOES
2012    did another thingy   |     HERE
2015    still rocking        |
==============================
Exhibition 1 
   * 2009
   * Stonehenge
   * Cool Copy
Exhibition 2
   * 2010
   * Asterix
   * Cool Copy
Exhibition 3 
   * 2012
   * Obelix
   * Cool Copy

My template looks like this:

<section id='<perch:content id="pageslug" type="hidden" />' xmlns:perch="https://www.w3.org/1999/html">
    <div class="sectionTitle">
        <h1>
            <perch:content id="pageTitle" type="hidden"/>
        </h1>
    </div>
    <div class="container" id='content-<perch:content id="pageslug" type="hidden" />'>
        <div class="row">
            <div class="col-md-6 col-sm-6 col-xs-12">
                <table class="table biographie">
                    <tbody>
                    <perch:blocks>
                        <perch:block type="zeitpunkt" label="Lebenslauf Eintrag hinzufügen">
                            <tr>
                                <td>
                                    <perch:content id="cvtime" type="text" label="Jahr / Zeitraum" />
                                </td>
                                <td>
                                    <perch:content id="cvtext" type="textarea" label="Was getan wurde" editor="markitup" markdown="true" size="s" />
                                </td>
                            </tr>
                        </perch:block>
                    </perch:blocks>
                    </tbody>
                </table>
            </div>
            <div class="col-md-6 col-sm-6 col-xs-12">
                <img src='<perch:content id="cvimage" label="Bild" type="image" />'
                     alt='<perch:content id="bildtitel" label="Bild Titel" type="text" />'
                     width="100%"/>
                <legend>
                    <perch:content type="text" id="legend" label="Bildunterschrift"/>
                </legend>
            </div>
        </div>
        <div class="exhibitions">
            <!-- here, I'd like to generate the list of exhibitions -->
        </div>
    </div>
</section>

The user should have three sections to edit in the backend:

  1. the list of CV entries
  2. the image
  3. the list of exhibitions

With the current layout/design, the CV list and the exhibitiuon list are mutually exclusive, i.e. you should not be able to put a cv line into the exhibitions list and vice versa.

As I cannot simply add another <perch:blocks> structure, how should I approach this?

Volker Kopetzky

Volker Kopetzky 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Should the exhibitions not be a region of their own?

Simon Clay

Simon Clay 127 points

You could use a repeater, like this:

<div class="exhibition">
  <perch:repeater id="exhibition_list" label="Images">
    <perch:content id="additional_cvtime" type="text" label="Jahr / Zeitraum" />
    <perch:content id="additional_title" type="text" label="Title" />
    <perch:content id="additional_cvtext2" type="textarea" label="Was getan wurde" editor="markitup" markdown="true" size="s" />
  </perch:repeater>
</div>

The problem is that the regions for each are singular and auto generated.

The index.php file has this code to generate the regions:


<?php $pageList = perch_pages_navigation( array( 'levels' => 1, 'skip-template' => true )); foreach ( $pageList as $item ) { $slug = ltrim( $item['pageSortPath'], "/" ); // prepare the page section perch_content_create("Inhalt", array( 'page' => $slug . ".php", 'template' => '_' . $slug . ".html", 'multiple' => false )); } ?>

Then, the pages themself will be put into the page with this code:

~~~

<?php foreach ($pageList as $page) {

    $slug = ltrim( $page['pageSortPath'], "/" );

    $queryOptions = array(
        'page' => $page['pagePath'],
        'template' => '_' . $slug . ".html",
    );

    PerchSystem::set_vars(array(
        'pageslug' => $slug,
        'pageTitle' => $page['pageTitle'],
        'pageModified' => $page['pageModified']
    ));

    // register region
    perch_content_custom("Inhalt" , $queryOptions);

} // end foreach ?>

~~

By using this approach, I limited myself to only one region per page (Inhalt) unless I intruduce additional qirks in the pages loop (if ($slug=='biography')), or maybe add another 'dummy' region to each page wich then would be left empty for all other pages. Each of these solutions/workaronds is adding too much complexity and clumsiness for my taste.

As this is my first encounter with perch, I might have overlooked a relevant feature, so any other approach on how to build a one-pager using multiple perch pages is welcome, too ;)

@ Simon Clay What would be the dummy explanation on the difference between blocks and repeaters?

Simon Clay

Simon Clay 127 points

Blocks will allow an editor to choose different types of content to add i.e.:

<perch:blocks>

<!--*Editor can add text*-->
  <perch:block type="text" label="Text">
    …
  </perch:block>

<!--*or another element*-->
  <perch:block type="quote" label="Pull quote">
    …
  </perch:block>

<!--*or an image etc*-->
  <perch:block type="image" label="Feature image">
    …
  </perch:block>

</perch:blocks>

Repeaters are for just a fixed set of fields that get repeated.

Thanx Simon!

That's good intel, so I will convert my blocks to a repeater and simply use another repeater for the exhibitions.

ouch, I wanted to select Simons first answer as solution, can the mod help here?