Create a grid layout
Managed by | Updated .
Prerequisites
- Collection has been crawled.
- Completed How-to-Guide: Customise a search result.
- Understanding of the Freemarker Templating Language.
- Understanding of the Funnelback data model.
- Download this file resultColumns.ftl.
- Download this file result.ftl.
Objective
Customise a search result layout to be displayed within a grid.
Steps
1. Upload result.ftl & resultColumns.ftl
- Load the Funnelback administration interface and select the the collection (search interface) you would like to customise.
- Open the file manager.
- Select Administer tab > Browse Collection Configuration Files
- Upload result.ftl file.
- Under Presenation (preview) section select Choose File and select the result.ftl file saved on your computer.
- Upload resultColumns.ftl file.
- Under Presenation (preview) section select Choose File and select the resultColumns.ftl file saved on your computer.
2. Import Result Template into Simple.ftl
- Under Presentation (preview) section select simple.ftl for editing.
This is the main search template file which handles the display of the entire search interface. - At the top of the file add this line after the existing imports.
This imports our new template library into the current file.<#import "result.ftl" as Result/>
- Locate the results block (the code between <@s.Results> and </@s.Results ).
Tip: To quick find the result block click within the file edit and press Ctrl(control)+f or mac ⌘(command)+f and search for s.Result . - Delete all the code within (including the li tag)
and replace with the following code.<li data-fb-result=${s.result.indexUrl}>
This code calls the GridView macro provided within result.ftl.<@Result.GridView />
- Click Save and publish
- Open the search page result and see how the result view has now changed and displays the text "Transform into a grid layout!" repeated for each result.
The provided result.ftl includes a few pre implemented macros;
- GridView - This is an empty macro which you will configure in the next set step "Define Grid Layout".
- Book; - This is an example result format for a book which has been predefined for you.
3. Define Grid Layout
- Under Presentation (preview) section select result.ftl for editing.
- Replace the code within the GridView macro with the following.
<@ResultColumns.ResultsColumns columnsNumber=3>
<@ResultColumns.ResultsColumnsIsOpen>
<li class="row" data-results-column-rank="${ResultColumns.resultsColumnsIndex!}">
<ol class="list-unstyled">
</@ResultColumns.ResultsColumnsIsOpen>
<#local cssColWidth = (12/ResultColumns.resultsColumnsNumber!1)?floor?c >
<li data-fb-result=${s.result.indexUrl} class="col-md-${cssColWidth!} columns-${ResultColumns.resultsColumnsNumber!}">
<@Book />
</li>
<@ResultColumns.ResultsColumnsIsClosed>
</ol>
</li>
</@ResultColumns.ResultsColumnsIsClosed>
</@ResultColumns.ResultsColumns>
This code will wrap the results with groupped html container rows which you can layout with CSS and most CSS grid systems. - Click Save and publish .
4. View & Test
- Go to the result page to see your new view the grid view layout.
Working Example
Was this artcle helpful?
Latest In this section