I am building a more or less simply search function in a website and the basics work fine. If I type in a search term the corresponding page is listed as a link in my results! My goal is to display not only the link to the page (containing the found search term) but also the paragraph in which the search term was found.
As I understand it so far:
The outcome ($result) gives me the page
On that page I need to initiate a search again (in my tamplate) with the search term ($query)
then I need to get the paragraph / parent / field of that search result
then render that paragraph / parent / field into text
Thanks for the link! That would be a nice option too. I am new to php and Kirby and don’t really get it integrated in my code. I guess I put your snipped into the search controller? if I do that I get an error in the search tamplate about the Undefined variable “$text”…
Thank’s a lot! It works perfectly with the function in the controller and the code you provided for the template!
Indeed I need a solution wich works even when my search is extended to different content fields. In my Search controller I use 3 different searches. First of all to define different search parameters and second to display search results in different sections.
I all ready tried to adapt the function for example the declaration field. This works fine but would mean that I need to write a lot of functions… If thats the only way – I of course will do it but I was wondering if there is a more light solution. I want to archive the displayed text for the search in general pages (fields: text) and in the position section (fields: declaration, implementation, references, notes) but not in the participants search.