2

I am using a variant of 'Page Content' to list all the children of the item based on page template. I am able to get the list using the below query. I am also able to fetch the fields of the children item. In this case they are Title and Content.

enter image description here

However, I am interested in getting the URL of the item. Any idea how to get the URL using query?

Edit: I need the child pages of an item. For e.g. we have a News parent page and it has several news detail pages of different dates. I want the list of news details page and their URL, so that I can extract content from each - maybe the element programmatically or not sure if it would be possible by sxa query. I want to extract the content so that I can print all the news detail pages in one single click on a Print All button.

4
  • 1
    Why do you need the url? If it is to get a link, you can check the "Is Link" on a field (like Title)..
    – Gatogordo
    Commented Nov 29, 2019 at 14:07
  • Thanks for replying.I need the page item URL. Actually I need to get the list of all the child pages under a parent node and then get their URLs so that it can be used for further use.
    – Varun
    Commented Nov 29, 2019 at 16:57
  • What do you mean with further use? You'll need to be more specific to get a good answer
    – Gatogordo
    Commented Nov 29, 2019 at 19:09
  • Sure Gatogordo. As mentioned, I need the child pages of an item. For e.g. we have a News parent page and it has several news detail pages of different dates. I want the list of news details page and their URL. I want the URL so that I can extract content from each may be the <main> element programmatically or not sure if it would be possible by sxa query. I want to extract the content so that I can print all the news detail pages in one single click. I.e on Print All button.
    – Varun
    Commented Nov 30, 2019 at 2:36

2 Answers 2

0

If I understand your question correctly you want to loop over all the items and display a few field (title, content) and the url (not as an actual link but really printed out).

In that case you are doing fine with the query variant and the Title and Content field variants as shown in your question. For the url, you have 3 options:

  • You could create an NVelocity template and use $item.Url. Although this will seem tempting you should not do this ;) First of all NVelocity is not that fast and mostly because this is not future proof (it is removed in SXA 9.3)
  • Just in case you would be already running on SXA 9.3, you could use Scriban. In that case it would be really easy as current item and it's url are build-in extensions
  • But as the first one is not so good, and you probably are not yet on 9.3 - there is a third option and that would be to use a custom token. Yes, custom.. so not ootb. But really easy to do and documented here: https://doc.sitecore.com/developers/sxa/18/sitecore-experience-accelerator/en/create-a-custom-token-for-a-rendering-variant.html

So in short: if you are on 9.3 go for Scriban. If not, write a custom token.

1
  • Thanks Gatogordo. I will give it a try.
    – Varun
    Commented Dec 4, 2019 at 6:15
0

There is one field in VariantSection/Section is IsLink Filed. its a Dropdown, please select Wrapped and check. enter image description here

Hope this will help you

1
  • Thanks Keyur. My requirement is: I need the page item URL. Actually I need to get the list of all the child pages under a parent node and then get their URLs so that it can be used for further use.
    – Varun
    Commented Nov 29, 2019 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.