0

Using Sitecore 8.2 along with SXA 1.2 rev. 161216, I am trying to add a simple SectionTitle (a title and a bit of HTML below it) rendering to the available renderings in SXA.

I followed a few tutorials, each of them presenting quite different approaches, still none worked. This is what I did,

Created the View

@using Sitecore.XA.Foundation.MarkupDecorator.Extensions
@using Sitecore.XA.Foundation.SitecoreExtensions.Extensions
@model myworkspace.Models.SectionTitle

<div @Html.Sxa().Component("section-title", Model.Attributes)>
  <div class="component-content text-green section-title">
      @Html.Sxa().Field("Title", Model.Item, Model.GetRenderingWebEditingParams())
      <span class="underline-shape-line"></span>
      <span class="underline-shape-disc"></span>
  </div>
</div>

Created the Model

public class SectionTitle : RenderingModelBase
{
    public SectionTitle() { }
    public string Title { get; set; }
}

Created the Controller

public class SectionTitleController : StandardController
{
    private readonly ISectionTitleRepository _repository;

    public SectionTitleController(ISectionTitleRepository repository)
    {
          _repository = repository;
    }

    protected override object GetModel()
    {
        return _repository.GetModel();
    }
}

Created a Repository class

(to be honest, I didn't fully understand why it is better than just ue CreateModel())

public interface ISectionTitleRepository: IModelRepository
{
}

public class SectionTitleRepository : ModelRepository, ISectionTitleRepository
{
    public override IRenderingModelBase GetModel()
    {
        SectionTitle model = new SectionTitle();
        FillBaseProperties(model);
        model.Title = GetTitle();
        return base.GetModel();
    }

    private string GetTitle()
    {
        return PageContext.Current[Templates.SectionTitle.Fields.Title];
    }
}

Created a Parameters Template

Called SectionTitle, inherits from IStyling and Standard Rendering Parameters

Created a Template

Called SectionTitle, with a section called Section and a field called Title (Rich Text)

Created a Controller Rendering

Controller: SectionTitle

Controller Action: Index

Parameters Template: The one created above

Datasource Location: query:$site/[@@name='Data']/[@@templatename='Text Folder']

Datasource Template: The template created above.

Still, when I try to add a new item in Experience Editor, I get

"Could not find the rendering in the HTML loaded from server"

I have tried lots of other configurations and always get this error, does someone have a hint ?

5
  • Is it a typo or you're missing one closing </div> tag in your component cshtml?
    – Marek Musielak
    Apr 24, 2017 at 13:19
  • Well seen, it's a typo ! Apr 24, 2017 at 13:20
  • Does your view have the exact same name as your rendering?
    – Gatogordo
    Apr 24, 2017 at 13:38
  • the view is called View.cshtml in the SectionTitle (exact same name as rendering) folder. After checking the logs, I get the same error as there (but in french :p), sitecore.stackexchange.com/questions/2973/… I'm trying the fixes proposed there... (no chance til now) Apr 24, 2017 at 13:49
  • Ok, there was the solution, I also miswrote the return value of GetModel(). Not sure if the question should be classified as duplicate or not... it has a different title and can thus can be found diagnosing different errors. I'll let the admins decide ! Muchas Gracias ;) Apr 24, 2017 at 14:23

2 Answers 2

0

Looking into the logs, it appeared I had the same error as here but in french. I solved it adding a new constructor to the controller,

public SectionTitleController()
    {
        _repository = new SectionTitleRepository();
    }

I also miswrote the return value of GetModel(), I was returning base.GetModel() instead of model.

0

In my particular case this error occured not on a csutom rendering but on any rendering. The reason turned to be the solr service that served the website search indexes service was not running (any more).

https://localhost:8662/solr/#/ was not accessible (port number may vary on your solr instance for your project)

Starting the involved solr service in windows services solved my issue.

Maybe it can help someone

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.