Repeater transformation with Categories

John Fu asked on January 22, 2015 06:09

Hi,

I’m repeating a bunch of documents with different Categories.

What I’m trying to achieve with the transformation is, display these documents and in the markup somehow, add the individual categories tagged as css classes.

So for example, document A is tagged “couples” and “families”, and document B is tagged “couples” and “business”, then in the transformation, it would generate something like the below:

For Document A: <a href=”documentA” class=”docitem couples families”>DocumentA</a>

For Document B: <a href=”documentB” class=”docitem couples business”>DocumentB</a>

Can this be done in transformations? Obviously it somehow needs to have some sort of loop to go through each of the tagged categories and then print them out. The question is how can it be done?

Thanks.

Recent Answers


Brenden Kehren answered on January 22, 2015 06:48

So you say "categories" and "tags", can you specify which one you are using?

Here is an example of getting categories via some custom code.

Here is an example of getting tags within a repeater (might be able to nest a repeater in the transformation)

1 votesVote for this answer Mark as a Correct answer

John Fu answered on January 22, 2015 07:16

Thanks Brenden,

I'm using Categories like one would use as tags. Mainly because the Repeater webpart has Categories built in as a content filter already.

The example offers a solution. But the one thing I don't like about the solution is that it requires added code in App_Code. Is there a way to keep it out of the App_Code? I don't like the idea of touching modifying files within App_Code because it restarts the site everytime I make a change.

I have a folder within the CMS folder specifically for custom code. Is it possible to put custom .cs code in there and have it work?

Thanks.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on January 22, 2015 07:42

If you plan to extent the CMSTransformation class then yes, it belongs in the App_Code directory. If you plan to use it in more than one place i.e.: macro, then yes, it belongs in the App_Code directory. If you only make the change once, it will be just fine, yes it will restart but same thing happens if you change the web.config.

The other, not so recommended, place to add this would be in the transformation itself wrapped in some < script runat="server" > tags. Essentially you'd copy the whole GetDocumentCategories() method in the OnInit or OnLoad event.

0 votesVote for this answer Mark as a Correct answer

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