Hi hope someone can give a little guidence.
I have a cs library creating assets for a DW 8.3. the Library.dll is being passed to the DW Application bin directly and all is cool.
I have an ItemType set at page level adding additional properties to each page created, extending the properties for the Page (I do similar for Paragraphs).
eg an audience type is used to configure page settings for a particular audience accessing the page (and relevent sub pages)
and an Item Type ItemList holds configuration data for each page, like a particular help desk phone number the audience should call,
the related Twitter feed script, the particular help desk emaill address for the audience type etc.
From here I want to create and set some custom Page (and Paragraph) Template Tags during the Page Output cycle
and render them in the HTML, all is good so far. I can render all the custom tags, and in a Loop all the "Item.Page.Attribute_List" tags...
<!--@LoopStart(Item.Page.Attribute_List)-->
<li><!--@Item.Page.Attribute_List.Page_Phone_Number--></li>
<li><!--@Item.Page.Attribute_List.Page_Advisor_Email--></li>
<li><!--@Item.Page.Attribute_List.Page_Twitter_Feed--></li>
<li><a href="<!--@Item.Page.Attribute_List.Page_FAQ_Page-->">FAQ page</a></li>
<li><a href="<!--@Item.Page.Attribute_List.Page_Reviews_Page-->">Reviews Page</a></li>
<!--@LoopEnd(Item.Page.Attribute_List)-->
When I come to get the "Item.Page.Attribute_List" in my Page.OnOutput, I need to get all these attributes and create seperate Template Tags
for each, since these are not available to the rendered page unless I Loop. ("Item.Page.Attribute_List" has only a Name field and a Value [3] corresponding the database Item ID)
It would be nice to be able to see a List<ItemEntry> within this object.
Do I have to go to the database to get these items? Or is there a better way?
Some sample code would be very welcome.
Here's mine:
DWPage.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dynamicweb;
using Dynamicweb.Rendering;
namespace XXXWeb.Library.Methods
{
[Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.Standard.Page.OnOutput)]
public class PageObserver : Dynamicweb.Extensibility.NotificationSubscriber
{
public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
{
if(args == null)
{
return;
}
var item = args as Dynamicweb.Notifications.Standard.Page.OnOutputArgs;
CheckTagCollection(item.template.Tags, item.template);
}
private void CheckTagCollection(TagCollection tagCollection, Template template)
{
if (tagCollection.ContainsTagName("Item.Page.Page_Audience_Type") || tagCollection.ContainsTagName("Item.Page.Attribute_List"))
{
var audienceTag = tagCollection.GetTagByName("Item.Page.Page_Audience_Type");
var pageAttributesTag = tagCollection.GetTagByName("Item.Page.Attribute_List");
// we create our new Page Tags from our ItemType Attribute List.
DisplayAttributeList(pageAttributesTag.Value, pageAttributesTag, template);
//We get the audience type for the page from the Page Item Type properties
DisplayAudienceType(audienceTag.Value.ToString(),template);
}
}
private void DisplayAttributeList(string ID, Tag list, Template template)
{
// It seems we need to lookup our properties from the ItemType data
string tagName = list.Name.ToString();
TagCollection newTags = new TagCollection();
//?????
var a = Dynamicweb.Content.Items.Item.GetItemById("ItemType_PGL_Page_Attributes", ID);
a.SerializeTo(?);
template.Tags.Add(newTags);
}
private void DisplayAudienceType(string p, Template t)
{
Dynamicweb.Rendering.Tag audienceTypeTag = new Tag();
audienceTypeTag.Name = "audienceTypeTag";
audienceTypeTag.Value = p;
t.Tags.Add(audienceTypeTag);
// Also maybe tickle a CSS file link along the way perhaps
Dynamicweb.Rendering.Tag cssTag = new Tag();
cssTag.Name = "cssTag";
cssTag.Value = p;
t.Tags.Add(cssTag);
}
}
}