Wednesday, 24 July 2013

Tridion Broker Query

In this blog post I am going to show you how you can easily create a broker query with various kinds of criteria specified. I will be using Tridion 2013 and Visual Studio 2010 in this case.

In my example I have a .NET user control, which is placed inside a Frontend project. Its goal is to list all the components from Tridion that are using a certain schema.

First of all, let’s start with the user control. Here is how mine looks like:


We create an unordered list and inside of it, is where the magic is going to happen. There we make a Repeater which will bind all the results from the query. These are going to be returned as list items, containing all the information, with the help of a Component Template.

Now let’s go to the code behind of this control and start with the main implementation that is the topic of the blog post. I am explaining everything with comments inside the code block bellow:


That’s it! Now we are ready to get all the components with schema, which we specified by its id, and display these as we wish. You can go on and give it a try.

Please, don't forget to:

  • add the user control to a page where you want to display the components
  • make sure that the components are published
  • make sure you have the right Tridion DLLs (netrtsn, Tridion.ContentDelivery.Configuration, Tridion.ContentDelivery, Tridion.ContentDelivery.Interop, xmogrt). It is imporant to have these in 32-bit or 64-bit depending on your project
  • make sure you have all the JARs from Tridion
  • make sure you have configured correctly the config files of Tridion
I hope you like the article and find it useful and interesting. If you have any questions, please do not hesitate to contact me.

1 comment: