PageType Field Data inside custom webpart ?

jason zerr asked on October 16, 2018 16:56

How can one get the data inside a page type to render with a custom webpart. Are there any examples of this somewhere ? Also when is it better to use a custom webpart vs a transformation on the pagetype with a webpart repeater.

Recent Answers


Brenden Kehren answered on October 16, 2018 17:02

Maybe explain a bit more what you are trying to accomplish. Are you wanting to list out some items or display details on a page?

Typically custom webparts are created to preform specific functionality which is not in an existing webpart. Listing or displaying data from a page type is already covered in virtually every webpart Kentico supplies.

0 votesVote for this answer Mark as a Correct answer

jason zerr answered on October 16, 2018 17:07

Hey Brenden I am trying to create a layout with custom webpart that uses data from two pagetypes and uses default data in-case their is no input by user. Think of more like a hero component accessing bussiness detail fields from one page type and background image and text from another.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 16, 2018 17:14 (last edited on December 10, 2019 02:31)

I'd suggest using a repeater to get the main object you want to display, then create a custom transformation method or custom macro to perform the rest of your queries. We do this scenario quite often. Take a look at an ecommerce site. There are

/products/brands/collections/types/product-detail

If you want to display the Collection name for a given product detail, you can simply use a macro in your transformation to get that data like so:

{%CurrentDocument.Parent.Parent.DocumentName|(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

jason zerr answered on October 16, 2018 21:21 (last edited on October 16, 2018 21:22)

Brenden, thanks I was able to render data with something similar, Now I am wondering How do you take care of default data or string empty checks ?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 17, 2018 07:17 (last edited on December 10, 2019 02:31)

Are you simply checking to see if a field is empty or do you want to provide default data when the form is opened/saved?

If simply checking for empty, you can again use a macro like so:

{%if(FieldName != "") { "it's not empty" } else { "it's empty" }|(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

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