Sitecore dictionary items Editable via page editor -
i trying implement sitecore dictionary items edited via pageeditor.
this approach.. need thoughts , suggestions.
to make simple , not mess pipelines, here simple way of doing.
normally sitecore translate example,
@sitecore.globalization.translate.text("somekey")
you can encapsulate translate custom class might
public static class customtranslate { public static string text(string key) { if (sitecore.context.pagemode.ispageeditorediting) { string val = string.empty; item currentitem = context.database.getitem(resourcescontroller.itemlookup()[key]); if (currentitem != null) { val = fieldrenderer.render(currentitem, "phrase"); } return val; } else return sitecore.globalization.translate.text(key); } }
the customtranslate.text returns fieldrenderer in pageedit mode else returns sitecore.globalization.translate.text
then in code can refer translations
@customtranslate.text("somekey")
the lookup can dictionary of key , item id shown in below code,
public static class resourcecontroller { public static dictionary itemlookup() { ///get dictionary path..etc.. code not included //read sitecore dictionary items sitecore.data.items.item[] items = sitecore.context.database.selectitems("fast:" + dictionarypath + "//*[@@templateid='{6d1cd897-1936-4a3a-a511-289a94c2a7b1}']"); //build dictionary<string,string> using sitecore item key , guid. items.all(y => { resourcedictionary.add(y["key"], y.id.guid.tostring()); return true;} // key,guid dictionary return resourcedictionary; } }
a simpler , easier approach ! thoughts, comments ?
Comments
Post a Comment