How can I render component link field in a DWT? - tridion

I have a schema containing a multi-value field of type component link.
How can I render this field (component link with its template) when I write a DWT TBB for this component?

A Component Link field links to a Component - it does not specify a template. So I'll assume you want to specify the Component Template to use on the DWT.
<!-- TemplateBeginRepeat name="Component.Fields.YourComponentLinkFieldName" -->
#RenderComponentPresentation(Field, "tcm:1-2-32")##
<!-- TemplateEndRepeat -->
So this loops over all values of the multi-value field names YourComponentLinkFieldName and render the Component linked in there with Component Template tcm:1-2-32.
All of these topics are relevant to your question:
Retrieving values of a linked component in Dreamweaver TBB - and making it SiteEditable
How to handle nested repeating regions in Dreamweaver TBBs in SDL Tridion 2011 SP1
Retrieving values of a linked component in Dreamweaver TBB - and making it SiteEditable
I suggest you read them and apply your understanding of them.

Related

Using several RenderComponentPresentations for XPM templates w/ Razor

As you probably already know, I'm working hard on some XPM templates with Razor. I've ran into another issue, this time concerning rendering components inside templates in order to make them siteEditable.
The following I'm not sure about. I've got a component which has a title field called "Title", and multivalue componentlink fields which consists of components with a title, description and image. Let's call this one "Linked USP" for now.
Currently this is being rendered by a Template called 'Page Banner', and it just iterates over fields with some If-loops to determine it's presentation, especially for the Title. In order for XPM to work, this template needs to render the component presentation of "Linked USP". So we've created a template called "[XPM] USP ITEM". - this Component template has the 'enable content editing TBB" added to it.
Now the issue arises when I want to make the Title Editable as well. Sounds straightforward, no? Not really - because when the parent template has got a "enable for content editing" TBB added, it will add <span> tags to all editable fields but the templates that gets invoked inside this template will also have <span> -tags, effectively bloating the html and making it impossible to edit the fields inside the RenderComponentPresentation because of duplicate <span>s.
Some code for your fun and to illustrate my issue:
<h1>#RenderComponentField("Title", 0)</h1>
#Foreach(var linkedUSP in Fields.USPS){
#RenderComponentPresentation("linkedUSP.ID", "tcm:10-1076-32")
}
This template has an enable Content edit TBB added.
now, for the RCP mentioned above, inside its [XPM] template:
<div class="title">#RenderComponentField("Title", 0)</div>
<p>#RenderComponentField("Description", 0)</p>
<tcdl:ComponentField name="img">
<img src="#img" alt="img.MetaData.alt">
</tcdl:ComponentField>
This one ALSO has the "Enable Content Edit" TBB added. On the front end this happens:
<div class="title"><span><span>Men</span></span></div>
Because the parent template also adds spans to the field.
So my question: how do i solve this? The Title field mentioned above has to be inside the parent template, but I can't create a special template for it becuase it is no component link. I can't get the TBB out of my RCP template, because it won't be editable that way. Interesting huh?
Can't I disable the spans inside template builder somehow?

Access fields in a template of components inside components inside components

I've a problem here. The structure that I have at the moment is:
ComponentA
FieldA1 - textField
CombonentsB - componentLink (multi-value)
FieldB1 - textField
ComponentC - componentLink
FieldC1 - textField
Now I am trying to place ComponentA with Template on a page.
I am using DWT Templating.
What I need is to access FieldC1 in the template.
I've already added the "Add Linked Components To Package" TBB in TemplateA.
I think it is identical to this one:
http://sdltridionworld.com/community/extension_overview/addcompstopackage.aspx
I can access FieldB1 in my template but not the fields further down in the hierarchy.
Do I have to write another TBB that includes the whole hiearchy, or should it work as expected and my access code is just wrong?
<!-- TemplateBeginRepeat name="ComponentsB" -->
##ComponentC.Fields.FieldC1##
<!-- TemplateEndRepeat -->
What can I do to make it work? Are there any other solutions then writing a new TBB?
=========== SOLUTION ============
After Nickoli Roussakov told me about the DGX, I managed to implement it correctly.
Here the code:
<!-- TemplateBeginRepeat name="ComponentsB" -->
##Get("ComponentsB[${TemplateRepeatIndex}].Fields.ComponentC.Fields.FieldC1")##
<!-- TemplateEndRepeat -->
GetLinkedComponents works only on the first level of component nesting because you can't go deeper than that with DWT syntax. Your options are to write a custom tbb that renders out the output needed down from componentB, or try Nuno's DGX extension (also on sdltridionworld) instead of GetLinkedComponents.

SDL Tridion taxonomy component count is off

I am new to Tridion and am facing an issue with the taxonomy.
As storage we are using file system and for taxonomy we have sql db.
Now, we have created State as Category with few keywords inside it. I have created schema and a component and have selected one of the keyword for classification. This associates the keyword with the component.
Now I have used the Tridion control with the uri of the State to retreive the taxonomy. It works fine, but the component count is showing as (0) instead of (1) since only one component is added in the bracket which is the normal behavior of tridion. I have published the taxonomy as well as the component.
You need to publish the Component that is using the Keyword. As far as I can see, the control is counting items on the Content Delivery side; not items in the Content Manager. I set up a simple example using the basic tag:
<tridion:TaxonomyControl
ID="taxBasicProperties"
TaxonomyURI="tcm:1-8-512"
runat="server">
</tridion:TaxonomyControl>
Result without the component published:
Sistema operativo (0)Android (0)iOS (0)Windows (0)
Result WITH component published:
Sistema operativo (1)Android (0)iOS (0)Windows (1)

Can we edit Page Metadata in Tridion using SiteEdit 2009?

In SDL Tridion 2009 SP1 we have Components that are added to Structure Group and Page Metadata which are then output on the Page as a Component Presentation. We have done this to allow users to set global content per site section without the need to add it to every single Page in the Structure Group.
When we output the Component with a Component Template with manual tags we get a red box around the Presentation and the tooltip of the SiteEdit box says “Removed”. When using the exact same Component Template in the Component Presentations tab and rendering that on the page the content is editable.
Is it possible using SiteEdit 2009 to inline edit a component added as Page/Structure Group metadata?
Note: We are aware of an outstanding bug in SDL Tridion 2009 SP1 that when you go to open a component added to Page/Structure Group metadata that it always opens it read-only. Could this be causing the issue?
It is possible to do this but you have to make sure that your markup is correct. I have done this before by marking the SiteEdit Component Presentation as QueryBased which seems to make SiteEdit ignore it's usual rules where the Component must be added in the Component Presentation list
<!-- Start SiteEdit Component Presentation: {
"ID" : "CP1",
"ComponentID" : tcm:32-204298",
"ComponentTemplateID" : "tcm:32-204519-32",
"Version" : "16",
"IsQueryBased" : true}
-->
You need to either:
Expose the metadata of the page in a "visible" area of your page with the correct SE markup
Open the page in CME and edit the Metadata there.
Tridion UI 2012 added a button with "Edit Metadata" functionality, but that's not available for SE 2009
Not through inline editing. You can of course open the Page editing popup and edit the metadata there.
Of course if you want to edit fields of the Component that you've linked in Page Metadata, you can just render out that Component Presentation into the HTML and mark it with the correct SiteEdit commands as Nuno suggests.

How to access componentlink field names in third level?

How to access componentlink field names in third level?
I have a schema which contains a field as embeddable schema, in that embeddable schema, I have a component link which is derived from another schema. How can i retrieve the field of that schema?
It really depends on the purpose of those field(s), perhaps you could provide some more information?
Another option not mentioned here is to write your own C# building block to add these 3rd level components to your package. By doing so you make it a lot simpler to work with them in your DWT layout.
For example if your third-level items are used to generate a list of office locations, you could write a C# block to obtain all the relevant office location components and add them to your package as a component list 'Locations' all you would simply need to do in your DWT is loop those items and provide the display you need.
Personally I don't like to use / add functions into DWT, I try to keep it as simple as possible, again if you can provide more information about your scenario that would generate a better answer for you from the community.
As far as I know, you need a special DWT TBB to get some control over your embedded/componentlinks. Maybe you could use Nuno's Get Extensions ? http://www.sdltridionworld.com/community/extension_overview/dreamweaver_get_extension.aspx
Or use Razor Mediator, perhaps:
http://www.sdltridionworld.com/community/2011_extensions/razormediator.aspx
To prevent having to use either the DGX (as MDa suggests) or write a C# TBB (as John Winter suggests), you can also simply call RenderComponentPresentation to render the linked Component with the template that you want to use.
<!-- TemplateBeginRepeat name="Component.Fields.LinkFieldName" -->
##RenderComponentPresentation(Field, "tcm:1-23-32")##
<!-- TemplateEndRepeat -->
Where tcm:1-23-32 it the TCM URI of a Component Template that simply renders the name of the Component as a hyperlink. Inside the DWT that you use in tcm:1-23-32 you can then simply refer to all fields and properties of the linked Component like Component.Title, Component.Fields.Field1, etc.
Note that the relevant topics have been covered already in these other questions/answers:
rendering the title of a linked component - Looping through the multiple component links to get the schema name of the linked component in Dreamweaver TBB in SDL Tridion 2011
getting values of a linked component - Retrieving values of a linked component in Dreamweaver TBB - and making it SiteEditable
handling nested embedded schemas - How to handle nested repeating regions in Dreamweaver TBBs in SDL Tridion 2011 SP1
If somehow these did not help you enough, I suggest you post the XML of your Component and the DWT that you're trying to make work.
Here a quick sample using C#
Session session = engine.GetSession();
Item componentItem = package.GetByName(Package.ComponentName);
Component component = new Component(new TcmUri(componentItem.GetValue("ID")), session);
ItemFields itemFields = new ItemFields(component.Content, component.Schema);
IEnumerable<ComponentLinkField> ie = itemFields.OfType<EmbeddedSchemaField>().OfType<ComponentLinkField>();
for (IEnumerator<ComponentLinkField> e = ie.GetEnumerator(); e.MoveNext(); ) {
Component linkedComponent = e.Current.Value;
}
By using Linq you can navigate through the fields structure really quick and get results. It will give you the Component Links in the third level, of course you can use the same to go deeper in the structure.

Resources