Path value of a page type dynamically in a Document Helper Query

Vincent Michael asked on April 29, 2022 18:43

How do I get the Path value of a page type dynamically in a Document Helper Query, using Xperience 13? See my codes below:

        return (List<TabswithUrlViewModel>)DocumentHelper.GetDocuments<Tab_accordion>()
              .OnCurrentSite()
              .OrderBy("NodeOrder", "NodeLevel")
              .Path("/abpWeb/Customer-Support/Download-Center/%", PathTypeEnum.Children)
              .Select(m => new TabswithUrlViewModel()
            {
                TabTitle = m.tab_item_title,
                TabContent = m.tab_item_content,
                TabToggle = m.tab_toggle,
                HeaderActiveClass = m.header_class_active
            })
            .ToList();

This path 1st parameter below is what I want to be fetching dynamically instead of using the static string value;

"/abpWeb/Customer-Support/Download-Center/%"

Recent Answers


Vincent Michael answered on May 2, 2022 16:55

How can we apply the use of Path Macro Expressions in the MVC code, as pasted in my example, to generate paths dynamically instead of writing them statically?

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 3, 2022 11:31

Based on what you want to get the path? Should it be current page's path? If yes, use the current document context. This is hard to tell - could you please explain what the code should be doing? Maybe it will make more sense for us and we may be able to give you some more tips.

0 votesVote for this answer Mark as a Correct answer

Vincent Michael answered on May 3, 2022 20:19

@Juraj Ondrus

What I wanted is simply a code or technique that can return that Path string for me dynamically in the sample code above, instead of the way it is currently:

.Path("/abpWeb/Customer-Support/Download-Center/%", PathTypeEnum.Children)

so my request is to use either code or any good technique to be returning this path string automatically: "/abpWeb/Customer-Support/Download-Center/%"

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 4, 2022 07:07

Vincent,

You still haven't answered Juraj's question though. Where does this hard coded path come from? Is it the current page? Is it a value the user selects in a widget? Where does this value /abpWeb/Customer-Support/Download-Center/ come from?

0 votesVote for this answer Mark as a Correct answer

Vincent Michael answered on May 4, 2022 08:47

This, /abpWeb/Customer-Support/Download-Center/% is the path (the NodeAliasPath) of the Page-Type whose contents I want to render on a page.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 4, 2022 09:35

@Vincent - so, the path should be the current page's path, correct?

1 votesVote for this answer Mark as a Correct answer

Vincent Michael answered on May 4, 2022 10:12

Yes @Juraj

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 9, 2022 08:07

Could you please also explain where and how you want to use the code - so we have the big picture? I cannot tell without knowing more as I do not know yet what options, context is available in your case. If it is a widget, maybe you could use this to access current page's data.

0 votesVote for this answer Mark as a Correct answer

Vincent Michael answered on May 10, 2022 06:17

This code is used in the Controller section to fetch all the values of a page type under that TreeNode. I just wanted to have another way of writing the NodeAliasPath parameter in the Path method dynamically with a code or even a macro expression. It actually works as it is presently.

Did you get me now?

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 10, 2022 07:33

Not really. To get the page object properties, like the NodeAliasPath, you need to get the page object instance at first - so, you are somehow contradicting your code. If you need to get the properties of the current page and work with the current page object then you be retrieveing the data context by using the PageDataContextRetriever service (requires manual initialization of the page data context for pages handled by custom routes based on page type URL patterns).
Or, when you look into the Dancing Goat sample project, there is something similar implemented in the ArticlesController.cs:

public IActionResult Index([FromServices] IPageDataContextRetriever dataContextRetriever, [FromServices] IPageUrlRetriever pageUrlRetriever, [FromServices] IPageAttachmentUrlRetriever attachmentUrlRetriever) {

var section = dataContextRetriever.Retrieve< TreeNode >().Page;
var articles = articleRepository.GetArticles(section.NodeAliasPath);

and then the section variable contains the NodeAliasPath property value.

1 votesVote for this answer Mark as a Correct answer

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