Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

locomotivecms-search

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

locomotivecms-search

  • 0.3.6
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

Setup

Open your Gemfile and add locomotive-cms search to it:

gem 'locomotivecms-search', require: 'locomotive/search/mongoid'

Check out the Activesearch gem to know which backends are available and how to configure them.

Run bundle install

Adding the search results page

[New way]

{% search_for params.query, per_page: 10, page: params.page %}

<p>{{ search.total_entries }} elements found.</p>

<ul>
{% for result in search.results %}
  <li><a href="/{{result.slug}}">{{ result.title }}</a></li>
{% endfor %}
</ul>

{% if search.total_pages > params.page %}
  <p>
    <a href="?page={{ params.page | plus: 1 }}&query={{ params.query }}">Next page</a>
  </p>
{% endif %}

{% endsearch_for %}

[Old way]

Create a new page that will display your search results. Its code might be something like this:

{% for result in site.search %}
  <li><a href="/{{result.slug}}">{{ result.title }}</a></li>
{% endfor %}

As you can see, when a search string is passed in the URL, you can fetch the results by using site.search. Choose a good slug, like "search".

Adding the search form

Anywhere on your site you can add a simple form to fire a search. This could be done on the homepage, on a page you are inheriting from, on even on a snippet. Just add this code:

<form action="/{{ locale }}/search" method="GET">
  <label for="search">Search</label>
  <input type="text" name="search" id="search">
  <input type="submit" value="Search">
</form>

The important part is the action parameter, since it must point to the slug of your search results page. Also, the name of the search input must be "search".

Search from the back-office

From the 0.3.0 version, this gem includes a search bar for your LocomotiveCMS back-office. This search bar uses the typeahead javascript plugin.

The only requirement is to have the LocomotiveCMS 2.5.x version installed.

In your LocomotiveCMS main application (the one embedding LocomotiveCMS), you need to add 2 files (or edit them if they already exist).

In the app/views/locomotive/shared/_main_app_head.html.haml file, add these 2 lines:

= javascript_include_tag  'locomotive/search_bar'
= stylesheet_link_tag     'locomotive/search_bar'

In the app/views/locomotive/shared/_main_app_header.html.haml file, add this line:

  = render 'locomotive/shared/search_bar'

Note for mongoid 2.x users

If you are using the mongoid engine and still on 2.x, you must use locomotivecms-search version ~> 0.0.5

This project rocks and uses MIT-LICENSE.

FAQs

Package last updated on 22 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc