Thursday, February 23, 2017

Don't write logic into your Views, use a Controller

BAD
The view contains 4 lines of Markup but 15 lines of code. Don't do that - it's better to use a Controller that contains an Action which contains the logic and returns a model to the view.
BETTER
Change your Sitecore presentation Item from View rendering to Controller rendering and set the Controller assembly path and action:
The action should contain all logic:
And the view only the markup:
But even the Model.Count == 0 is too much logic. The model could contain a field "HasItems" that checks the model count, but this can be accepted. After refactoring, the view contains more lines of Markup than logic.

How-to structure Sitecore dictionary entries

Working with hundreds of translation labels for dozens of different website components (e.g. search, forms, settings, notifications, etc.) requires a certain amount of housekeeping.
Thus, structuring your dictionary entries into appropriate folders is always a good idea!
Two things matter here:
  1. the dictionary entry is contextualized by applying a use-case oriented folder structure (/Modules/Direct Links/...)
  2. the key of the dictionary entry resembles the actual item path, allowing a developer to easily find a given dictionary entry

And that's all you need to know about structuring Sitecore's dictionary entries.
Happy coding! (smile)

Wednesday, February 22, 2017

Thursday, February 9, 2017

How add Recaptcha on MVC layouts

For this please follow Sitecore documentation:
https://doc.sitecore.net/web_forms_for_marketers/working_with_actions_and_validations/fields/add_and_customize_a_recaptcha_field_on_mvc_layouts

Wednesday, February 8, 2017

Solr Configuration for providing search suggestions

Hi All,

Today we discuss how we configure solr for provide search suggestion.
For that I follow 2 blogs which are listed below the blog.

https://blog.horizontalintegration.com/2015/07/20/configuring-solr-to-provide-search-suggestions/

http://www.nttdatasitecore.com/Blog/2017/January/Faceted-Autocomplete-for-a-Sitecore-Multilingual-site-using-SOLR-Suggester-API

By using help of these blog I can configure solr with auto suggest. I use 1st blog for setup solr and using 2nd blog Building jQuery Autocomplete jquery : jquery function for autocomplete suggestion.

Note:
1.Keep in mind while follow first blog for updating solrconfig.xml field str contain the name of the field for example:
<searchComponent name="suggest" class="solr.SuggestComponent">
    <lst name="suggester">
        <str name="name">fuzzySuggester</str>
       ...
        <str name="field">page_title_t</str>
    ...
    </lst>
    <lst name="suggester">
        <str name="name">infixSuggester</str>
      ...
        <str name="field">page_title_t</str>
       ...
    </lst>
</searchComponent>

2. While using 2nd blog jquery function its give cross platform error , solution also provide in that blog but i am not able to resolve that so i use my solution that are below:
<script type="text/javascript">
        $('#search-field').autocomplete({
            source: function (request, response) {
                var currentLanguage = 'en';
                var url = "http://localhost:8983/solr/custom_index_autocomplete/suggest?suggest.q=" + request.term + "&suggest.cfq=" + currentLanguage + "&wt=json&json.wrf=?";
                $.getJSON(url, function (data) {
                    //response($.map(data.suggest.suggester[request.term].suggestions, function (value) { return value.term }));
                    response($.map(data.suggest.fuzzySuggester[request.term].suggestions, function (value) { return value.term }));
                });
            }
        });
</script>

3. For combined multiple indexes for autosuggestion please follow as below:

   <script type="text/javascript">
        $('#search-field').autocomplete({
            source: function (request, response) {
                var currentLanguage = 'en';
                var url = "http://localhost:8983/solr/custom_index_autocomplete/suggest?suggest.q=" + request.term + "&suggest.cfq=" + currentLanguage + "&wt=json&json.wrf=?";
                var url1 = "http://localhost:8038/solr/content/suggest?suggest.q=" + request.term + "&suggest.cfq=" + currentLanguage + "&wt=json&json.wrf=?";

                var res;
                var res1;
                $.getJSON(url, function (data) {
                    res = data.suggest.fuzzySuggester[request.term].suggestions;
                    $.getJSON(url1, function (data) {
                        res1 = res.concat(data.suggest.fuzzySuggester[request.term].suggestions);
                        response($.map(res1, function (value)
                        { return value.term }
                           ));
                    });
                });
            }
        });
    </script>