8

I am migrating my old project to DXA 1.4. I am using Keyword fields in Schemas. While binding with default Tag Schema I am getting Keyword description instead of Keyword title. Reason for this is KeywordMap function with line

string displayText = String.IsNullOrEmpty(keyword.Description) ? keyword.Title : keyword.Description;

My question is what is the best way to get this behavior changed while binding a Model keeping in mind that it should always to ready to migrate to latest version? I can think of 2 way to do this:

  1. Create your own Tag and ModelBuilder class, register it to modelBuilderPipeline and override the functions required.
  2. Create your own Schema for Keyword field and create your own ModelBuilder class and add it also to modelBuilderPipeline to bind the model field.

Personally, I favor option 1. Please suggest, if anyone have faced similar issue. Thanks in advance.

4
  • 1
    Since DXA is open source, you could fork it and fix the issue yourself by modifying the line of code you found. And then create a pull request so the DXA people can adopt your change. The problem though is that some people may like the current functionality.
    – Quirijn
    Jul 22, 2016 at 19:37
  • You are right Quirijn. Whenever we develop a new website, current functionality is good to use. Actually, we are migrating our project from Tridion 2013(custom implementation) to Web 8 and DXA. We have old content with new implementation. Jul 23, 2016 at 11:58
  • Did you get anywhere with this? I can't get my ModelBuilder to register, it just keeps using the DefaultModelBuilder.
    – Andy Blyth
    Aug 18, 2016 at 8:35
  • Hi Andy, I have already implemented. Let me write a answer for my own question, that may help others with similar query. You can see the Tag <modelBuilderPipeline> in main web.config. Here you can add your modelbuilder class similar to the default one. Aug 18, 2016 at 11:08

1 Answer 1

2

Best option to override model binding methods is:

  1. Implement a separate model builder class and register it along with default model builder. Write your own functions to override the default behavior in your custom model builder.
    enter image description here

In this way model builder will be executed 2 times for every model.

  1. Implement a custom model builder and override functions to change the default behavior. Remove Default model builder and register your custom model builder. enter image description here

In this way model builder will be executed only 1 time for every model.

Here overall idea is to keep your custom code separate from default DXA code so that there will be no issue while migrating to latest version of DXA. Please share your suggestions.

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.