Is it possible to get a loop templates parent/owner template from the TemplateV2 class?
Something like this:
Template myLoopTemplate = myTemplate.GetLoop(“MyLoop”);
If (myLoopTemplate.ParentTemplate.TagExists(“MyTag”))
//Found!
namespace Dynamicweb.Samples.LibYou can then use the extension method as follows:
{
public static class TemplateExtensions
{
public static Dynamicweb.Templatev2.Template ParentTemplate(this Dynamicweb.Templatev2.Template template)
{
Type myType = typeof(Dynamicweb.Templatev2.Template);
PropertyInfo field = myType.GetProperty("Parent", BindingFlags.Instance | BindingFlags.NonPublic);
return (Dynamicweb.Templatev2.Template)field.GetValue(template, null);
}
}
}
The extension method ParentTemplate retuns the Parent property of your child template using reflection. You can then use it to call TagExists as you normally would.using Dynamicweb.Samples.Lib;... Dynamicweb.Templatev2.Template childTemplate = template.GetLoop("MyLoop");
if (childTemplate.ParentTemplate().TagExists("ParentTag"))
{
template.SetTag("ParentTag", "Some Value");
}
You must be logged in to post in the forum