How to get components of a template in SDL Tridion 2011 SP1 - tridion

I am newbie in Tridion. I am looking for some sample code for a TBB to get all components for a component template. I have seen examples of how to get components of a page or from a folder but not for this.
I could get the count by using object.GetListUsingItems(filter).SelectNodes(*).Count in my template, but I need a way to iterate all components and get Title or other attributes of Components.
Please advise.

You cannot get all components for a template in one go, you need to look first at which Schemas are associated with this component template, then get all components for each schema. Be aware of Blueprint contexts when doing this.
I'm slightly confused as to what you're trying to achieve with this, if you want to do this as part of a publishing action you would very quickly end up with massive publish transactions with many components in it.
If you want more attributes than exposed in Lists, then use GetUsingItems instead - but be aware that this is a considerably slower operation with a lot more database interactions than getting a list.

Related

Nested MVC templates

I have a standard SpringMVC ModelAndView. In one of my model objects I have an ArrayList of objects that I want to have different ui rendering capabilities. (different date formats, different css classes, divs, spans, etc....) Right now my template(view) looks like this:
<c:forEach items="${object.objectList}" var="item">
${item.toHtml}
</c:forEach>
My different items of course generate their own HTML. This of course is very, very wrong as I have html code in my java code which I hate. Is there anyway to have a template(view) for each item? Item is an abstract superclass, and I want each concrete implementation to have it's own view.
This is not a direct solution, but I think that the tutorial here and the corresponding GitHub project here might give you enough of an idea to build the solution yourself. It does not directly address your concern, but it includes a nice little tutorial on custom template tags within a Spring project. In principal, you can create libraries of custom tags, which depending on the parameters you pass them, can create any styled HTML or JavaScript programatically, without having to store the HTML in your database (which can have its own inherent issues).

What's a Non-Delivery Custom Renderer?

SDL Live Content describes the use case for Renderers as "manipulating the output produced by the rendering process" for Component Presentations. This falls between Content Manager and Content Delivery, specifically under Content Distribution / Publishing.
Rather than adding a Template Building Block (TBB) to all templates, we can use a custom renderer to "globally" change all CP's output. We can also use a renderer to publish item types not currently rendered. We can add a custom resolver for this item type along with a custom renderer and CD-side code.
We would implement IRenderer under Tridion.ContentManager.Publishing.Rendering in a .NET project and add the resulting dll to the CMS's GAC.
Questions
I can see how we would use a renderer to maybe manipulate or even wrap all outputted markup or maybe wrap all CPs.
Is this for "raw" manipulation of whatever our templates output? In other words, do we get access to any of the CM or CD APIs?
Does this renderer logic apply to all publications and templates in a given CMS instance?
The documentation refers to item types, are those Tridion item types such as TBBs?
Bart Koopman also describes how Custom Renderers work in the context of the other extension points in How To Tackle Integrations article on SDLTridionWorld.
I understand is distinct from Delivery-Side Renderers described by Jaime Santos Alcón?
This is indeed something that would be executed every time the standard renderer is invoked. While the use case for Custom Resolvers is easier to understand, the principles are the same and they're both part of the Publishing Pipeline.
I will always advise that instead of creating a custom renderer that will execute every time you render a template, you should use a Template Building Block that is added to all of your templates with that same functionality. Creating a custom renderer will likely be forgotten at some point in time and then you'll wonder why the output is different all of a sudden when nothing changed.

UGC in Dynamic Component Presentations?

I am having a problem using the UGC framework in conjunction with dynamic component presentations.
When I publish a CP as 'embedded on page', my UGC tags are converted from to nicely and I am able to leave ratings etc. However, if I create a dynamic version of the same CT/CP, what gets deployed to the Broker, is the same component presentation, with the stripped out.
Is there a limitation here that I am not aware of, or maybe some missing configuration?
Any thoughts would be very welcome.
I think you will need to check the output format of your Dynamic CT - Make sure it is set to the same as your target (REL, ASP.NET, JSP etc), and not set to None or HTML

Access a component's fields from a custom deployer

I'm trying to create a custom deployer in Tridion 2011 SP1 that can index a component to a solr instance once published. Everything is working fine but I've come across a bit of a problem with the way it indexes the components fields.
I can access the meta data fields okay by using the Component.getCustomMeta() method and parsing the XML. Accessing the normal fields however does not seem to be possible without reading in the file that is being output and parsing the output. This is not entirely feasible as the markup may change and it seems to be a long way around doing what should (hopefully) be a simple thing.
I've had a trawl through the docs and there doesn't seem to be anything available to get the field values so am I at a loss here and will need to parse the output or am I missing something somewhere?
Content fields are not exposed as such on the delivery side, content is exposed as, not surprisingly, "content".
If you really need the fields, you need to:
Produce a "parseable" output for your component presentations
Parse the component presentations as they get published.
Look at implementations like DD4T for similar approaches.
In short - you cannot do it, because Tridion does not expose it Out of the Box. The only way to do it is by changing the content output format through a template.
We have done an alternative workaround to achieve for the similar requirement. One down side with the implementation is extra rendering of Component Presentations in XML and duplicate of xml storage in broker.
Here is what we have done:
Created a Dynamic CT (XML representation of content) GetComponentAsXML and mapped to all schemas
All the Page Templates has a C# TBB that looks up the content that we need to push to SOLR
C# TBB does the RenderComponentPresentation with above Dynamic CT GetComponentAsXML, this pushes the XML (engine.RenderComponentPresentation(component.Id, componentTemplateURI)
Deployer now gets the content in xml format, in addition to the other type of component presentations (like ascx, emebedded on page etc..)
Hope this information helps.

Implementing Navigation Properties in Entity Framework

Hey folks,
I've been learning MVC 2 and I have pretty much everything understood except for the model part of things, I understand what the model is but actually implementing it has me confused.
Here's my situation, I have my DB which has 3 tables;
Ideas - table of ideas
Tags - table of tags
IdeaTag - link table connecting the above 2 tables via FKs
So when using the Entity Framework (.edmx) designer in VS2010 I get 2 classes created in the Designer, which obviously map to my DB tables and Navigation Properties in Idea for Tags & Idea for Tag.
So this is all fine until I actually try to add tags to an idea, what's the best practise for dealing with Navigation Properties? I wanted to add a Textbox which will then map to the Tags property in the Idea class but I'm unsure how I'd go about this.
Most of the MVC tutorials which discuss EF or Linq to SQL are quite basic.
If there are any suggestions for tutorials or video tutorials which discuss dealing Navigation Properties and how best to deal with them I'd gladly take it on board. Alternatively if there is a better way to implement this I'd happily look into that too.
Seeing as this is basically a Many to Many relationship, check out the accepted answer on this question.
It covers the scenario you are looking for. In your case 'ID' is probably the actual tag, i.e. "Entity Framework" or something.
Using the approach in that sample you can have a textbox, with a comma (or something else) delimited list of tag names. Splitting the contents of the textbox gives you an array of tags that should be in the Idea.Tags collection after you're done.
The only complication you have is I guess, you want to automatically create 'new' tags. So perhaps you'll probably need to check whether the Tag exists before attaching it (to add it to the Idea.Tags collection), if it doesn't exist instead of attaching it you would simply add it, so the new tag gets inserted.

Resources