Filtering Content on a page

Please put this code

dump($data);

into your template and let me know what you get after submitting the form?

it displayed this on top:


Array
(
    [ort] => Hamburg
)


so value is right

Now! It seems to work :slight_smile: I don´t why, put it filtering right

Thank you very much :slight_smile: Can´t believe it works now

Just one thing i noticed now is that that the footer is gone, after filtering. Any idea on that?

it has something to do with this pagination script, so when delete it. All is fine


			<div class="row text-left small_pad">
			<div class="col-xs-12  col-lg-12">	
<?php if($nom_list->pagination()->hasPages()): ?>
<nav class="pagination">

  <?php if($nom_list->pagination()->hasNextPage()): ?>
  <a class="next" href="<?php echo $nom_list->pagination()->nextPageURL() ?>">&lsaquo; weitere Jobs</a>
  <?php endif ?>
	


  <?php if($nom_list->pagination()->hasPrevPage()): ?>
  <a class="prev" href="<?php echo $nom_list->pagination()->prevPageURL() ?>">vorherige Jobs  &rsaquo;</a>
  <?php endif ?>

</nav>
<?php endif ?>
				
			</div>	
			</div>


Do i have to ad it here in the Controller:


 $nom_list = $page->children()->flip()->visible()->filter(function($child) use($keys, $data)


not sure how

Problem is that you paginate your complete list of jobs but not the filtered one. Change your controller like this.

<?php

return function($site, $pages, $page) {

  $ort = $page->children()->pluck('ort', ',', true);
  $keys = array('ort');

  // return all children if nothing is selected
  $nom_list = $page->children()->flip()->visible();

  // if there is a post request, filter the projects collection
  if(r::is('POST') && $data = get()) {
    $nom_list = $page->children()->visible()->filter(function($child) use($keys, $data) {

      // loop through the post request
      foreach($data as $key => $value) {

        // only act if the value is not empty and the key is valid
        if($value && in_array($key, $keys)) {

          // return false if the child page's category and value don't match
          if(!$match = $child->$key() == $value) {
            return false;
          }
        }
      }

      // otherwise return the child page
      return $child;

    });
  }
  $nom_list = $nom_list->paginate(6);
  $pagination = $nom_list->pagination();
  return compact('nom_list', 'ort', 'data', 'pagination');
};

And remove the pagination line from the template.

I copy your code to my controller but get a blank site with this template:



<?php snippet('header') ?>

	<div class="container small_pad  min_h">
		<div class="row"><div class="trenner"></div></div>	
		

		<div class="row-fluid small_pad">
			<form id="filters" method="post">
			Einsatzort: 
  			<select name="ort" onchange="this.form.submit()">
    		<option selected value="">Stadt auswählen</option>
    		<?php foreach($ort as $item): ?>
      		<?php if(!$item) continue ?>
      		<option<?php e(isset($data['ort']) && $data['ort'] == $item, ' selected') ?> value="<?php echo $item ?>"><?php echo $item?>				</option>
    		<?php endforeach ?>
  			</select>
			</form>	
		</div>	
		<div class="row small_pad">
				<?php foreach($nom_list as $proj):?>
				<div class=" col-sm-12 col-md-6 col-lg-6  wow fadeIn"  data-wow-delay="0.5s" data-wow-duration="1.5s">
				<div class="teaser_box">
				<h2><span class="white_t"><?php echo $proj->title() ?></span></h2>	
				<p>Einsatzort:  <span class="subtitle"><?php echo $proj->ort() ?></span></p>
				<p><?php echo excerpt($proj->beschreibung(), 100) ?></p>
				<p><a class="link_b" href="<?php echo $proj->url() ?>">JETZT ANSEHEN<span class="arrow_icon"></span></a></p>
				</div>
				</div>
				<?php endforeach ?>	
			</div>	
		
		<div class="row text-left small_pad">
			<div class="col-xs-12  col-lg-12">	
			<?php if($nom_list->pagination()->hasPages()): ?>
			<nav class="pagination">

  			<?php if($nom_list->pagination()->hasNextPage()): ?>
  			<a class="next" href="<?php echo $nom_list->pagination()->nextPageURL() ?>">&lsaquo; weitere Jobs</a>
  			<?php endif ?>
	
  			<?php if($nom_list->pagination()->hasPrevPage()): ?>
  			<a class="prev" href="<?php echo $nom_list->pagination()->prevPageURL() ?>">vorherige Jobs &rsaquo;</a>
  			<?php endif ?>
			</nav>
			<?php endif ?>				
			</div>	
		</div>
			
			
	</div>

<?php snippet('footer') ?>


I corrected an extra parenthesis in the controller above, please try again.

Worked perfect now. Thank you for you time, really appreciate it

I tried using this code in kirby 3.6 to filter pages using dropdown option but I got undefined variable data,
I changed visible to listed. Is there any workaround for it