Site not filtering

Hi,

I am trying to build a navigation menu to filter my projects. I have tried following the tutorial on YouTube and also consulting the web but I’m not able to solve my problem.

My home.php looks as follows:

<?php snippet('header') ?>
<?php
$filterBy = param('filter');
$projectsPage = page('projects');
$projects = $projectsPage
		->children()
		->listed();

if (!empty($filterBy)) {
		$projects = $projects->filter(function ($child) use ($filterBy) {
				$typology = $child->typology()->toString();
				return $filterBy === $typology;
		});
}
?>

<div class="wrapper">
	<div class="container-fluid projects p-0">
		<?php foreach ($projectsPage->children() as $project): ?>
			<?php snippet('project', compact('project')) ?>
		<?php endforeach ?>
	</div>
</div>



<?php snippet('footer') ?>

I have tried building a navigation bar, but my URLs just output all the projects no matter what the filter says.

For example, the URL website.test/projects/filter:Interior doesn’t filter anything. It just displays all the projects.

My project.yml looks like this:

title: Project

columns:
  - width: 1/5
    sections:
      image:
        type: files
        headline: Cover Image
        help: Upload image titled 'cover' to make it the project cover.
        template: cover-image
        max: 1
        layout: cards
        info: "{{ file.alt }} / {{ file.dimensions }}"
        image:
          ratio: 4/3
          cover: true

  - width: 1/2
    sections:
      info:
        type: fields
        fields:
          icon:
            label: Icon
            type: files
            help: Upload icon
            max: 1
            layout: cards
            info: "{{ file.dimensions }}"
            image:
              ratio: 4/3
              cover: true
          typology:
            label: Typology
            type: select
            options:
              Architecture: Architecture
              Architecture Residential: Architecture Residential
              Architecture Commercial: Architecture Commercial
              Master Planning: Master Planning
              Interior: Interior
              Interior Residential: Interior Residential
              Interior Commercial: Interior Commercial
              Interior Amenities: Interior Amenities
              Landscape: Landscape
            icon: tag
            required: true
          year:
            label: Design & Construction
            type: text
            icon: clock
          projectStatus:
            label: Status
            type: select
            options:
              Ongoing: Ongoing
              Completed: Completed
              Upcoming: Upcoming
          plotArea:
            label: Plot Area
            type: text
            width: 1/2
            icon: square
            required: true
          builtArea:
            label: Built Up Area
            type: text
            width: 1/2
            icon: circle
            required: true
          levels:
            label: Levels
            type: text
            width: 1/2
            icon: number
          location:
            label: Location
            type: text
            icon: location
          text:
            label: Summary
            type: textarea
            help: Short introduction to the project
            icon: text
            size: large

  - width: 1/2
    sections:
      gallery:
        headline: Project Images
        type: files
        layout: cards
        template: gallery-image
        info: "{{ file.alt }} / {{ file.dimensions }}"
        image:
          ratio: 1/1
          cover: true

Can someone help me with what I’m doing wrong? Even the hardcoded URLs don’t seem to output anything.

You are not using your filtered projects in your loop.

Got it, thank you!!!