Jump to content
texobyte

Unorganized List Using Repeater Field Help

Recommended Posts

In my template I have an UL (see code example 1) which I am converting to the ProcessWire CMS. Now I am unsure how to do this... and I have done the code on the repeater via the docs example (see code example 2) but I am not getting any results. My backend is setup with a repeater field called home_slider and inside the repeater is: [ image is sliderimg title is slider_title and text is slider_text].

 

Thanks!

CODE EXAMPLE 1:

<ul class="orbit-container">
  <button aria-label="previous" class="orbit-previous"><span class="show-for-sr">Previous Slide</span></button>
  <button aria-label="next" class="orbit-next"><span class="show-for-sr">Next Slide</span></button>
  <li class="orbit-slide">
    <div class="clearfix">
      <div class="small-12 large-10 large-centered columns">
        <div class="featured-image float-left"> 
          <img src="/assets/img/sans-graphic.jpg" style="height:340px;width:auto;" alt="Scrolling Featured Images"/></div>
        <div class="featured-text">
          <h3>SANS</h3>
          <p>The Submarine Acoustic Navigation System Beacon is an undersea, bottom-mounted...</p>
          <a href="/technology.html" class="button">Read More</a>
        </div>
      </div>
    </div>
  </li>
  <li class="orbit-slide">
    <div class="clearfix">
      <div class="small-12 large-10 large-centered columns">
        <div class="featured-image float-left">
          <img src="/assets/img/smart.jpg" style="height:340px;width:auto;" alt="Scrolling Featured Images"/>
        </div>
        <div class="featured-text">
          <h3>SMART</h3>
          <p>Standardized Metrics Assesments of Readiness and Training is an analysis tool...</p>
          <a href="/technology.html" class="button">Read More</a>
        </div>
      </div>
    </div>
  </li>
  <li class="orbit-slide">
    <div class="clearfix">
      <div class="small-12 large-10 large-centered columns">
        <div class="featured-image float-left">
          <img src="/assets/img/acms/acms-2.png" style="height:340px;width:auto;" alt="Scrolling Featured Images"/>
        </div>
        <div class="featured-text">
          <h3>ACMS</h3>
          <p>Advanced Contact Management Systems aids commanding officers in gathering actionable sonar information...</p>
          <a href="/technology.html" class="button">Read More</a>
        </div>
      </div>
    </div>
  </li>
</ul>

CODE EXAMPLE 2:

<? foreach($page->home_sliders as $home_slider) {
  <li class='orbit-slide'>
      <div class='clearfix'>
          <div class='small-12 large-10 large-centered columns'>
              <div class='featured-image float-left'>
              	echo "<img src='{$home_slider->sliderimg}' style='height:340px;width:auto;' alt='Scrolling Featured Images'/>";
           	  </div>
              <div class='featured-text'>
                  echo "<h3>{$home_slider->slider_title}</h3>";
                  echo "<p>{$home_slider->slider_text}</p>";
                  echo "<a href='{$home_slider->slider_btn_url}' class='button'>Read More</a>";
              </div>
          </div>
      </div>
  </li>
  }	
?>

 

Share this post


Link to post
Share on other sites
48 minutes ago, texobyte said:

$home_slider->sliderimg

would need to be

$home_slider->sliderimg->url

or

$home_slider->sliderimg->first()->url

depending on if the image field is single or multi
  • Like 2

Share this post


Link to post
Share on other sites

I think the problem here is the way you are mixing PHP and HTML together:

<? foreach($page->home_sliders as $home_slider) {
  <li class='orbit-slide'>

This isn't valid PHP - you need to either echo all the HTML or switch in and out of PHP like so...

<?php foreach($page->home_sliders as $home_slider): ?>
    <li class="orbit-slide">
    ...more HTML...
<?php endforeach; ?>

As an aside, the short PHP open tag <? is discouraged - the short echo tag <?= is okay though.

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      This is a module I made as an experiment a while ago and never got around to releasing publicly. At the time it was prompted by discussions around using Repeater fields for "page builder" purposes, where the depth feature could possibly be used for elements that would be nested inside other elements. I thought it would be useful to enforce some depth rules and translate the depth data into a multi-dimensional array structure.
      I'm not using this module anywhere myself but maybe it's useful to somebody.
      Repeater Depth Helper
      This module does two things relating to Repeater fields that have the "Item depth" option enabled:
      It enforces some depth rules for Repeater fields on save. Those rules are:
      The first item must have a depth of zero. Each item depth must not be more than one greater than previous item depth. It provides a RepeaterPageArray::getDepthStructure helper method that returns a nested depth structure for a Repeater field value.
      Helper method
      The module adds a RepeaterPageArray::getDepthStructure method that returns a multi-dimensional array where the key is the page ID and the value is an array of nested "child" items, or null if there are no nested children.
      Example

      The module doesn't make any assumptions about how you might want to use the depth structure array, but here is a way you might use it to output a nested unordered list.
      // Output a nested unordered list from a depth structure array function outputNestedList($depth_structure, $repeater_items) { $out = "<ul>"; foreach($depth_structure as $page_id => $nested_children) { $out .= "<li>" . $repeater_items->get("id=$page_id")->title; // Go recursive if there are nested children if(is_array($nested_children)) $out .= outputNestedList($nested_children, $repeater_items); $out .= "</li>"; } $out .= "</ul>"; return $out; } $repeater_items = $page->my_repeater; $depth_structure = $repeater_items->getDepthStructure(); echo outputNestedList($depth_structure, $repeater_items);
       
      https://github.com/Toutouwai/RepeaterDepthHelper
      https://modules.processwire.com/modules/repeater-depth-helper/
    • By ICF Church
      Hi 👋
      Anyone else having this problem?
      Requirements:
      - Repeater (matrix & normal) with mutlilanguage fields (text, textarea…) 
      - Backend language set to something other than default (ie. German) 
      Reproduce:
      - Add a new repeater Item (ajax, I found no way to possible to disable it with matrix)

      (Notice how the default language tab is active instead of the backend language…)
      - Write something into the (default language) field
      - Try to save, if field is required, this will not work. If not required, then when reloading, the content will be inside the backend language field, instead of the default language field who was (presumably) active
      Analysis:
      When  loading  a new repeater element with ajax, the default langue tab is active, but the backend language inputfield is visible (with no visual indication). When writing into the field, it will populate the backend language. When manually clicking on the default language tab (which is already active), the field will switch to the actual default language field (which is [now] empty) (that can now be populated…)
      Also Notice, the labels of the elements to be added are in default language as well instead of the translated label (images instead of Bilder)…
      ProcessWire 3.0.148, Profields 0.0.5…
      Is it my system configuration, or does anyone else have the same issue? This is a screen recording of the problem:
      Issue: https://github.com/processwire/processwire-issues/issues/1179

      Screen Recording 2020-02-25 at 14.18.31.mov
    • By Flashmaster82
      Is it possible to just show a list (page reference) but without any radio buttons? Or a drop down but the references is not selectable? The items needs to be references but the main thing is that its just a list. Please help!

    • By neonwired
      I have a front end form for creating new pages, repeater and repeater matrix field don't seem to save any data. I was considering handling the data manually but can't seem to get anything useful from the post data, are there any methods i can use?
    • By neophron
      Hi,
      I'm having trouble with a maybe simple code:
      I created a repeater (gallery_logos_links) and a repeater matrix (RepeaterMatrix_unternehmen). The repeater (gallery_logos_links) is inside the matrix repeater as a matrix type.
      The repeater matrix type is: gallery_logos_links and the image filed from the repeater is single_image.
       
      This my code:
      <?php foreach ($page->RepeaterMatrix_unternehmen as $item) { if ($item->type == 'gallery_logos_links') { echo " {foreach($item->repeater_logos_links as $logo)} <img src='{$logo->single_image->url}' alt='{$logo->single_image->description}' width='400'> {endforeach} "; } else if ($item->type == 'some_stuff') { echo"  
       
×
×
  • Create New...