Jump to content

aagd

Members
  • Posts

    49
  • Joined

  • Last visited

Posts posted by aagd

  1. Hello @ukyo, thanks for sharing this. I tried the module with your example code. The content and tag params work fine, but others like size etc. didn't output anything. Shouldn't they appear as CSS classes? Am I missing something?

    (PW 3.0.229, PHP 8.1 & 8.2)

    <?php echo component('heading', [
        'content' => 'Hello World!',
        'tag' => 'h3',
        'size' => 'text-large',
    ]);?>

     

  2. 7 minutes ago, bernhard said:

    That works great for PW but not sure if that also works for WordPress as I heard it does weird things with hardcoded hosts all over?!

    About handling the hardcoded URLs in WP, there was this: WordPress sucks and I want to kick you in your teeth! - Page 5 - Beer Garden - ProcessWire Support Forums

    I'm still using MAMP PRO with .local URLs. It has it's limits, eg. with the choice of DBs, PHP versions etc. I guess I'll switch to DDEV, too, one day...

  3. For very complex templates I (miss)use the Auto Template Stubs module, to manually copy/paste a list of all used fields to the template head comments, so if there are a lot of generic fieldnames (as flydev recommended above), I don't have to look them up all the time. The module creates the whole info in separate files, very easy to copy & paste. If you need fields inside a Repeater, they're also available in separate files. Looks something like this then:

    /**
     * Template: contact (Contact)
     *
     * @property string $title Page Title
     * @property string $text_ml_01 Headline
     * @property string $textarea_ml_01 Body
     * @property Pageimages $images_01 Images
     * @property Pagefiles $files_ml_01 Files
     */
    • Like 2
  4. In your screenshot under Item Headers, where you wrote {address_2} - That's where you define it. Make sure to save the field settings page, and reload the page editor of the content page to update. Also you have to set it for each matrix type separately. It looks like the field editor and the page editor don't match here, maybe you're editing the wrong field or matrix type here.

  5. Like @bernhard said, a repeater works well for this. The output in the template could look like this:

    <ul>
    <?php foreach($page->repeater_faq as $faq):?>
      <li>
        <h2><?=$faq->question?></h2>
        <p><?=$faq->answer?></p>
      </li>
    <?php endforeach;?>
    </ul>

    If you want to optimize the FAQ page for Google SEO you could additionally add the content in JSON format (not visible on the page).

    More Info: https://developers.google.com/search/docs/advanced/structured-data/faqpage

    This is what I usually use:

    <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "FAQPage",
      "mainEntity": [
    <?php
    $items = $page->repeater_faq;
    $item_count = count($items);
    foreach($items as $key => $value):?>
        {
          "@type": "Question",
          "name": <?=json_encode($value->question)?>,
          "acceptedAnswer": {
            "@type": "Answer",
            "text": <?=json_encode($value->answer)?>
          }
        }<?php if ($key === $item_count - 1){echo "\n";} else {echo ",\n";} ?>
    <?php endforeach;?>
      ]
    }
    </script>

     

    • Like 4
    • Thanks 1
  6. For larger sites I mostly use generic, numbered fieldnames like text_ml_01 (ml for multilanguage) which I might generate via API. Then in the templates I change the labels to something more meaningful and via AutoTemplateStubs I copy the complete field info with labels into the php templates, looks sth. like:

    /**
     * Template: basic-page (Basic)
     *
     * @property string $title Titel
     * @property string $text_ml_01 Headline
     * @property string $textarea_ml_01 Intro
     * @property string $body_01 Content
     * @property string $text_ml_02 CTA Button Label
     * @property mixed $url_ml_01 CTA Button URL
     * @property Pagefiles $files_ml_01 Linked Files
    */

    For smaller sites I prefer more custom fieldnames.

    • Like 4
  7. In the RepeaterMatrix field create two repeater matrix item types: cta1 & cta2. They don't even have to have any fields, i guess.

    In the template file that should output the repeater items you can output them like this:

    <?php
    
    foreach($page->repeater_matrix_field as $item){
    
      if ($item->type == "cta1"){
        echo wireRenderFile("Call-to-Action01.php");
      }
    
      if ($item->type == "cta2"){
        echo wireRenderFile("Call-to-Action02.php");
      }
    }
    
    ?>

    RepeaterMatrix is a pro module, though. Not Core.

    • Like 2
×
×
  • Create New...