Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Widgets /

Discuss SilverStripe Widgets.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

SearchForm in a widget?


Go to End


1783 Views

Avatar
JosefBlow

Community Member, 1 Post

18 April 2011 at 10:46pm

Hi all,

I'm trying to add a blog search tool using some code which I've found in one of my old site implementations (I've no idea where I found this code or if it ever worked?!).

I have the following files..

SearchWidget.php

<?php

/**
 * A simple widget that just shows a search box
 * @package blog
 */
class SearchWidget extends Widget {
	
	static $title = 'Search';
	
	static $cmsTitle = 'Blog Search';
	
	static $description = 'Shows a search option on the sidebar. This feature uses the standard site search module, so ensure that all other pages have "Show in search?" disabled unless you wish for those pages to feature in the search results.';

	/**
	 * Return an absolute URL based on the BlogHolder
	 * that this widget is located on.
	 * 
	 * @return string
	 */
}

?>

and
SearchWidget.ss

<ul>
  <li>$SearchForm</li>
</ul>

The widget is happily available with the Blog module of the CMS, but after nudging around in various directions, I've just hit a wall and can't get it to run.
I'm running SS v2.4.5 and I've enabled search with FulltextSearchable::enable();
I can also call $SearchForm from within another template eg. Page.ss succesfully.

Anyone got any ideas? I'm stumped!

Thanks in advance...