Accessing Hierarchical parent field

John Fu asked on September 22, 2015 04:49

I have a Hierarchical Viewer set up to display news content laid out by year -> months.

What I want to do is, in the Months links, I want to add a data attribute to include the year. So it transforms to something like <a data-date="2015 January">January

Which means, in my child transformation, I need to access the parent node's document name. I'm not having very much success in doing so. Can anyone help me with the transformation syntax?

Thanks.

Correct Answer

Brenden Kehren answered on September 22, 2015 05:10

If you know where in the url string it is you can use a simple split method on the NodeAliasPath field like so:

Your url is /news/year/month/news-item

<a data-date='<%# Eval("NodeAliasPath").ToString().Split('/')[2] %>'>January</a>

2 votesVote for this answer Unmark Correct answer

Recent Answers


Jeroen Fürst answered on September 22, 2015 08:30

Sounds like you are overengineering this one :) why not simply use the newsreleasedate column with a to date string "YYYY"?

0 votesVote for this answer Mark as a Correct answer

John Fu answered on September 22, 2015 08:38

Because "News" was just an abstract example and not the page type I'm actually applying this to. But thanks anyways. :)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.