c# - How can I add a new custom standard value token for sitecore branch templates? -
sitecore comes several standard custom value tokens when creating branch templates (i.e. $name
name of new item, $parentid
, id of parent).
is there anyway add new variables?
specifically want variable allow me access items path when added?
there sitecore blog post add custom standard values tokens in sitecore asp.net cms tbh, it's wrong (not sure why sitecore insist on producing "untested prototype(s)" time in these posts?!).
for reason guy jumping though various hoops decompile source , recreate (apart form fact makes code fragile should default behaviour change), unnecessary.
you can add new variable in few lines of code:
public class newvariablesreplacer : mastervariablesreplacer { public override string replace(string text, item targetitem) { //still need assert these here sitecore.diagnostics.assert.argumentnotnull(text, "text"); sitecore.diagnostics.assert.argumentnotnull(targetitem, "targetitem"); string temptxt = text; if (text.contains("$path")) { sitecore.diagnostics.assert.argumentnotnull(targetitem.paths, "targetitem.paths"); sitecore.diagnostics.assert.argumentnotnull(targetitem.paths.fullpath, "targetitem.paths.fullpath"); temptxt = text.replace("$path", targetitem.paths.fullpath); } //do do. return base.replace(temptxt, targetitem); } }
this works without decompiling because retains base functionality calling base.replace(text, targetitem);
.
you need alter default behaviour in xml in blog post:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <settings> <setting name="mastervariablesreplacer"> <patch:attribute name="value">sitecore.sharedsource.data.newvariablesreplacer ,sitecore.sharedsource</patch:attribute> </setting> </settings> </sitecore> </configuration>
Comments
Post a Comment