MrClan
MrClan

Reputation: 6790

Kentico - Displaying child items through transformations

I've a situation where there is a conditional case where the editor can pick the layout of the child items.

enter image description here

As can be seen from the image above, NewsItems is of type NewsContainer which provides the option for the layout of the child items of type NewItem. If the picked layout is of type, two items per row , the child items should be displayed vertically otherwise horizontally. The image below shows the transformation structure, where I need to access the properties of child news items.

enter image description here

Any help would be appreciated. Thanks.

PS: Kentico version: 10

UPDATES based on comments As per Roman's comment, I tried this, but still nothing appears in the output:

enter image description here

enter image description here

enter image description here

Applying individual transformations directly to the Transformation field of the repeater, produces the output, but it does not work, when using the macro.

Upvotes: 0

Views: 588

Answers (4)

Chetan Sharma
Chetan Sharma

Reputation: 1442

A better approach would be to conditionally populate transformation field using Macros. Something like this.

{% CurrentDocument.ApplyTransformation( ([YOURCONDITION] ? "[TRANSFORMATION_A]" : "[TRANFORMATION_B]") ) %}

Upvotes: 1

Trevor F
Trevor F

Reputation: 1437

Roman's method is clean, however if you purely want to do it in one transformation, this is what you would do.

<%# IfCompare(Eval("Layout"), "horizontal", "The content if it's NOT horizontal", "the content if it IS horizontal") %>

The IfCompare is an odd ball that it's 'false' is first and 'true' is second (hate that).

You can put all your logic in the "" then, OR you can make life a little easier if you're okay with some duplicate code and just display both and hide whichever is applicable

<div class="horizontalLayout <%# IfCompare(Eval("Layout"), "horizontal", "hidden", "") %>">
  Horizontal Here
</div>
<div class="verticalLayout <%# IfCompare(Eval("Layout"), "horizontal", "", "hidden") %>">
  Vertical Layout here
</div>

See Transformation method references

Upvotes: 0

Roman Hutnyk
Roman Hutnyk

Reputation: 1549

You could implement two separate transformations and use their code names as values in the Layout drop down. Now you should place some listing web part (repeater, uni viewer, etc.) on the 'container' page and enter {%Layout%} macro into web part transformation field.

Upvotes: 1

JanH
JanH

Reputation: 519

I am a bit confused by your description. The transformation would be applied for those News1-4 pages right? So you need to access the layout property of the parent page, not child page, correct? If so, I would recommend to switch to Text/XML transformation type and use this macro:

{%Documents[Documents[NodeAliasPath].Parent.NodeAliasPath].GetValue("LayoutField")%}

and just FYI from your screenshot the NewsItems page doesn't seem to be a container page type -> it's more probably content only page type that can't list standard pages.

Upvotes: 1

Related Questions