Issue trying to use Datasource Template in Sitecore sublayout; getting empty Sublayout.Datasource -


we've been trying "componentize" our sitecore solution move forward, in prep transitioning page editor usage (woot! finally!), we're still practically working page templates may inheritance-based composites of page specific fields, plus 1:many of these componentized templates. example of how looks in our solution below -- banner feature carousel , featured cartoon of these new components we're creating:

base templates showing components

in interest of trying move away using sitecore.context.item (as reminded this post) i've started filling in datasource template field on sublayouts new components, , seems i've got appropriate connections made between presentation details, sitecore sublayout , .net code file (as far can tell; again, we're newer working way).

i've tried setting base class these components per this post nick allen, here's i'm running problem: when execute code, base class finding component sublayout appropriately (the whole "this.parent sublayout" thing) but, when go interrogate sublayout.datasource property, it's empty string. here's code (so far) base class:

public class componentbase : system.web.ui.usercontrol {     private sublayout sublayout { { return parent sublayout; } }      public item datasourceitem      {                   {              return sublayout != null && !string.isnullorempty(sublayout.datasource) ?              sitecore.context.database.getitem(sublayout.datasource) : sitecore.context.item;          }      } } 

i'm apparently missing interplay between datasource template field in sitecore sublayout, , how translates datasource. because these component templates being used compose page templates? thinking datasource resolve page template on component in question being used, perhaps that's misunderstanding.

if give me hints of things check or point me resources might use further, i'd appreciate it. i've done quite bit of asking googs, myself, not getting that's helping.

thank in advance, sitecore friends!

it looks have configured allowed templates sublayout in steps describe above. tells sitecore; 'allow user select items based on these templates sublayout'. alone not set data source on items using sublayout. still need go presentation details items using sublayout, select sublayout , set datasource property (within content editor go presentation > details > [sublayout] > data source).

my answer question gives source code needed retrieve datasource item , iterate through sitecore controls on sublayout setting of item propertys.

here code:

public class sublayoutbase : usercontrol {     private item _datasource;      public item datasource     {                 {             if (_datasource == null)             {                 if (parent sublayout)                 {                     _datasource =                         sitecore.context.database.getitem(((sublayout)parent).datasource);                 }                 if (_datasource == null)                 {                     _datasource = sitecore.context.item;                 }             }             return _datasource;         }     }      protected override void onload(eventargs e)     {         foreach (control c in controls)         {             setfieldrenderers(datasource, c);         }         base.onload(e);     }      private void setfieldrenderers(item item, control control)     {         if (item != null)         {             var ctrl = control sitecore.web.ui.webcontrol;             if (ctrl != null && !string.isnullorempty(ctrl.datasource))             {                 //don't set source item if datasource has been set.                  return;             }             if (control fieldrenderer)             {                 var fr = (fieldrenderer)control;                 fr.item = item;             }             else if (control image)             {                 var img = (image)control;                 img.item = item;             }             else if (control link)             {                 var link = (link)control;                 link.item = item;             }             else if (control text)             {                 var text = (text)control;                 text.item = item;             }             else             {                 foreach (control childcontrol in control.controls)                 {                     setfieldrenderers(item, childcontrol);                 }             }         }     } } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -