Jump to content

simple site search without module


stanoliver
 Share

Recommended Posts

Hi! I tried to implement a simple site search like in the regular site profile by Ryan.

http://demo.processwire.com/regular/

I checked out the code on github but I could not make it work for my site. Probably because Ryan uses some advanced output strategy and uikit specific stuff which I don't use or understand.

For my site I just use:

- 1 template (name: templatetoparea.php) for the toparea of my site

- 1 template (name: templatemainare.php) for the main content of my site

- 1 template (name: templatefooterarea.php) for the footerarea of my site.

Also I have prepared two empty templates:

- 1 template (name: templatesearch.php) for the search itself

- 1 template (name: templatelistsearch.php) for listing the search results

May somebody could let me know how to implement a very basic site search like in the regular site profile without using any module or complicated output strategies.

Two things would be a must have:

- The search should work with standard repeaters (where most of my content lives)

- The search results/hits should be listed and the search word(s) should have a yellow colored background (inline css is fine) 

Link to comment
Share on other sites

Hey stanoliver!

First of all, it's difficult to say exactly how to set this up without knowing how your site has been set up etc. but if you're looking for a simple solution, you might want to take a look at the search template in the "classic" site profile: https://github.com/processwire/processwire/blob/master/site-classic/templates/search.php. This is a very bare-bones approach, though, and as such it doesn't handle things like those highlights – but it might be a sensible starting point for your own custom feature. Just modify the fields to search from etc.

I know you said that you'd like to achieve this without a module, but I do still think that SearchEngine would make sense here. It does quite a bit for you out of the box.

Hope this helps a bit.

Link to comment
Share on other sites

18 hours ago, stanoliver said:

For my site I just use:

- 1 template (name: templatetoparea.php) for the toparea of my site

- 1 template (name: templatemainare.php) for the main content of my site

- 1 template (name: templatefooterarea.php) for the footerarea of my site.

Not related to search, but: Are these really three templates? i.e. do you really use them as PW-templates, or just as partials that you include() in the template?

18 hours ago, stanoliver said:

The search should work with standard repeaters (where most of my content lives)

Perhaps this is useful: https://processwire.com/blog/posts/processwire-3.0.91-core-updates/

$pages->find("FieldtypeTextarea|FieldtypeText|FieldtypePageTitle%=coffee");

or this: 

 

18 hours ago, stanoliver said:

- The search results/hits should be listed and the search word(s) should have a yellow colored background (inline css is fine) 

Here's an example with PHP: https://stackoverflow.com/questions/9373023/how-can-i-get-a-summary-string-around-a-search-query-within-a-longer-string

Here's a little JS lib: https://markjs.io/

  • Like 1
Link to comment
Share on other sites

@dragan Your question made sense I am sorry for confusement.

Actually the real templates are like:

- templatehome.php

- templatebasicpage.php

The templates "templatetoparea.php" and "templatefooterarea.php" are included/are partials.

The template "mainarea.pp" made no sense at all. Sorry for confusing you.

Thanks for your help so far I will try out your guys hints.

Link to comment
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
 Share

×
×
  • Create New...