Developer forum

Forum » Templates » Tag suggestions

Tag suggestions

Sebastian Dammark
Reply

Would these tags be a good addition to the template tags:

  • Ancestor(Item.WhateverName)
  • AncestorOrSelf(Item.WhateverName)
  • Descendant(Item.WhateverName)
  • DescendantOrSelf(Item.WhateverName)
  • Parent(Item.WhateverName)

// Sebastian


Replies

 
Mikkel Ricky
Reply

Are they self-documenting?

Please elaborate on why they are needed and how they are to be used? I have good guesses, but I'd like to be sure what you're thinking.

Best regards,
Mikkel

 
Sebastian Dammark
Reply
  • Ancestor(Item.WhateverName)
    Retrive Item.WhateverName which isn't empty from nearest ancestor page
  • AncestorOrSelf(Item.WhateverName)
    Retrive Item.WhateverName which isn't empty from nearest ancestor-or-self page
  • Descendant(Item.WhateverName)
    Retrive Item.WhateverName which isn't empty from nearest descendant page
  • DescendantOrSelf(Item.WhateverName)
    Retrive Item.WhateverName which isn't empty from nearest descendant-or-self page
  • Parent(Item.WhateverName)
    Retrive Item.WhateverName which isn't empty from parent page

Like this ?

 
Sten Hougaard
Reply

So you would be able to pull items from the tree of items using the relation between the items to "navigate" to the item to pull out?

If for instance I have this structure:

  1. father (itemtype male)
    1. son (itemtype male)
    2. daughter (itemtype female)
  2. mother (itemtype female)

And you are rendering "son" you would be able in the template of "son" to fetch "father" using this pseudo code:

Parent(itemtypeFather)

Would that retrieve at Loop? Or?

This looks like XSLT Xpath sort of functionality?

Am I right or...? :-)


Med venlig hilsen/Best regards,

Sten Hougaard
 

 
Nicolai Høeg Pedersen
Reply

Well, this kind of functionality will be something you can do in Razor.

I've changed the API a little for 8.6 so you can do like this in a Razor template:

var aValue = Dynamicweb.Frontend.Page.FindPage(123).Parent.Item["FieldName"];
var bValue = Dynamicweb.Frontend.Page.FindPage(123).Parent.PropertyItem["FieldName"];
foreach (Dynamicweb.Frontend.Page p in Dynamicweb.Frontend.Page.FindPage(123).Children) {
 var otherValue = p.Item["FieldName"];
 var otherValue2 = p.PropertyItem["FieldName"];
}

I can give you some code you can add to your Razor template today that will giv you access to these information.

BR Nicolai

 
Morten Bengtson
Reply

Hi Nicolai,

Would you consider implementing something that is more like what Sebastian suggested?

Being able to access ancestor properties (PropertyItem) is something we often need in order to provide some "fallback" values. I'm not sure about how the Descendant and DescendantOrSelf should work (or what a good use case would be), but the other ones would be very useful (Parent, Ancestor, AncestorOrSelf) - with website properties as the root ancestor.

I know that we can code everything ourselves, but some helper methods would be nice in order to limit the amount of custom code needed for common tasks like this :)

@Sebastian, if you use items for page properties then the page properties will be available as attributes in your navigation XML and you can do this using good old XSLT. I'm not sure if this is the solution you are looking for though, since you can only use the values inside the scope of the navigation template (unless you are able to do some tricks with snippets).

BR Morten

 

You must be logged in to post in the forum