Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
I guess you would need to add an extension method for your content, something like
public static FundTemplateBlock FundBlock(this MyContent content)
{
//Load and return your block
}
and include this in your convention
Hi Eric,
For that, you need to do some level of customization. Create an IniitializationModule and add you custom property to index like this
[InitializableModule]
[ModuleDependency(typeof(IndexingModule))]
public class SearchInitialization : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
SearchClient.Instance.Conventions
.ForInstancesOf<MyPage>()
.IncludeField(x => x.FundTemplateContent());
}
}
Then, in your method, FundTemplateContent()
get your block from ContentReference property and return content to index it. (see below example)
public static string FundTemplateContent(this MyPage page)
{
var fundTemplate = string.Empty;
if (page?.FundTemplate == null || ContentReference.IsNullOrEmpty(page.FundTemplate))
return fundTemplate;
var content = ContentLoader.Service.Get<FundTemplateBlock>(page.FundTemplate);
if (content != null)
{
fundTemplate = content.Property1; //string property
fundTemplate += content.Property2; //string property
}
return fundTemplate;
}
Note: Above code is not completely tested. This is a sample code :)
Hope this will help.
This worked. Thanks. Made a couple of small changes to get it working. See working code below.
[InitializableModule]
[ModuleDependency(typeof(IndexingModule))]
public class SearchInitialization : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
SearchClient.Instance.Conventions
.ForInstancesOf<FundDetailsPage>()
.IncludeField(x => x.FundTemplateContent(x));
}
public void Uninitialize(InitializationEngine context)
{}
}
And my FundTemplateContent method inside my FundDetailsPage
public string FundTemplateContent(FundDetailsPage page)
{
var fundTemplate = string.Empty;
if (page?.FundTemplate == null ||
ContentReference.IsNullOrEmpty(page.FundTemplate))
{ return fundTemplate; }
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
var content = contentLoader.Get<FundTemplateBlock>(page.FundTemplate);
if (content != null)
{
fundTemplate = content. ///string field;
... //all other string fields
}
return fundTemplate;
}
Episerver version 11.12
We are using find to retrieve some content based on search text. I can index content blocks on my page that are added to a Content Area if they are marked with the [IndexInContentAreas] attribute, but it doesn't seem to index content blocks that are added as ContentReference type (see sample below). These blocks are also decorated with the [IndexInContentAreas] attribute but don't return results.
How do I get FIND to index the contents of the block in a ContentReference?