Implement "search" functionlity in kirby

hello everyone,
i want to implement search functionality in kirby so from the official documents i create on empty file search.txt and created search.php in templet file.
here is my code of search form.

and here is my templet code
i am getting perfect value that i have searched in search bar at templet page when i press enter
by doing this i am getting black page with error in console.

if i need to search that keyword in whole site, am I on right way?

You use $site() , I think it must be $site->search() :slight_smile:

Also, when you post code, can you do it inline (so in your post) with three backticks? It’s much easier to read and debug that way.

i have already used $site()->search();

but still not able to do simple search functionlity :frowning:

Pls. remove the parenthesis after $site and turn on debugging in your config.php.

What error do you get?

now i am getting path of content files without using foreach .
i just simple echo results and getting all the files name which contains that keywords from content part.

Pls post your final code as code block so that we can test it. Thank you.

      $results = $site->search($search);
     echo $results;

result displays as a single text line having break tag.
i think i am not getting desired output. :frowning:

You are echoing an object. You have to use a foreach loop to loop through the results.

Edit: Please wrap code blocks within three backticks (`) each on a separate line before and after the code. You can inspect your last post by clicking on the pencil icon to see what it should look like. Thanks for your understanding, it makes code much more readable.

or use var_dump($result) to show the object.