How to access componentlink field names in third level? - tridion

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.

Related

VS2008/ASP.NET 3.5 - How to create dynamic webforms

The question in a nutshell: Is there a way to add forms dynamically to a aspx-page? I know how to add controls to an existing form, but how to add a whole form?
Bckground:
I am "forced" to work in Visual Studio 2008 and I want to create a controller, which builds a page depending from the list of elements a model gives it (e.g.: the list may contain a paragraph, an image, another paragraph, a parapgraph again, a form and so on).
This works fine for the first examples as I am able to add them to the inner-html of a div-container.
Thinking about ways to generate a form like this (innerHTML += form), I feel I'd be throwing the few possible advantages ASP I can see (compared to PHP) out of the window in terms of input validation and so on. But I can't find a way to generate a "real, server-run" form. The same goes for gridviews, but I guess the solution may be similar.
A possible workaround would be to create an empty form
<form runat="server" id="dummyForm">...
and add controls to it dynamically. The obvious(?) downside to this would be, that I couldn't change its position (at least I wouldn't know how) in relation to the other content elements.
Another downside would be that I would be limited to one form per page and that may or may not be sufficient. If it wasn't I would starting to add several empty dummy-forms and would start indexing them and all of that doesn't look very cool to me.
Is there a more elegant way to a solution?
TIA
Simon
You can't add more than once server side Form tag in single aspx file
(in run time or design time)
maybe this article help you to generate dynamic forms :
https://msdn.microsoft.com/en-us/library/aa479330.aspx

How can I override 'base_edit' view for a type using portal_factory?

It seems that when I use the portal_factory tool for creating an instance of a type it disregards the view I've specified to override base_edit.
Here's what I've got setup:
Alias from edit to base_edit in the types tool.
View class that renders the view.
ZCML that that hooks on the view class to the appropriate interface.
Content class that implements the appropriate interface.
I know my overridden base_edit view works because it renders:
Once the object has been created it renders.
When I disable the portal_factory tool for the type.
When I use another name like custom_edit it also renders the overridden view, despite the type being enabled in the portal_factory tool.
Changing the alias to ##base_edit works too.
this way zope traversing makes an adapter lookup instead of attribute access and your edit view will be used.
afaik the ## forces an adapter lookup, without ## the first object thru acquisition is called and then an adapter
cc #juriejan
You don't need to customized the base_edit.cpt, you simply need to create a new CMF skin template called yourtypenamenormalized_edit.pt, where "yourtypenamenormalized" is your portal_type name lowercase and without spaces.
The original Archetype base_edit.cpt will look for a template called this way before applying all default macros.
After that I suggest you to fill this new template with all the code you'll find inside the default template, that is edit_macro.pt, then start to apply your changes.
Commonly the only macro you'll want to override is the body macro.

Rendering a z3cform Wizard as a standalone view

Plone/Zope's z3cforms inherit from BrowserPage, and therefore should be able to be rendered without the use of an additional View and View Class. When I try to do this, the form renders fine, but none of the form's fields appear. I am trying to solve why this occurs. Keep in mind this example is using collective.z3cform.wizard, which essentially provides two classes, a Wizard and a Step. A Wizard is a Form (capital F) that mostly provides the machinery to glue the Steps together and maintain state with sessions, and a Step is just a Form.
To me, it feels like either the macro is incorrect, the context is wrong, or there needs to be some wrapping/unwrapping of the form. Basically, I feel like there's some one magic line of code or piece of information I'm missing, which is often the case with Plone.
When the form is wired up to use a separate view (which is redundant), the form renders fine with all the fields showing.
Since I understand this is complex, I've built an example-only standalone package on GitHub that showcases the problem. If you install this package into a stock Plone site with buildout, you will get three views:
http://localhost:8080/Plone/working
http://localhost:8080/Plone/almost
http://localhost:8080/Plone/broken
The working view requires a separate view and a whole-template-wrapping TAL tag, which is both kludge and redundant...but it works and renders the form with all of its fields.
The broken view is wired up how it should be, with the form instance representing the view itself, with the template defined in the Wizard class.
The almost view is identical to the broken view, except that the template is associated with the Wizard's Step rather than the Wizard itself. This results in a broken render, but the form renders with all of its fields.
I hope someone can help me trace down why exactly it is that the broken view renders the form, complete with buttons, but none of the form's fields.
Thank you in advance.
Your broken view does not render the fields because it does not try to render the current step. The default wizard template has something like this in it:
<div tal:define="form nocall:view/currentStep"
tal:replace="structure form/render" />
which looks up the current step and renders it. But you've overridden that with your own template which just calls the ploneform-macros, which is a generic z3c.form thing that knows nothing about the existence of steps.
You should stick with the default wizard template instead of overriding it, or if you need to customize it you should copy the default wizard.pt from collective.z3cform.wizard as a starting point.
Meanwhile, your 'almost' view is indeed almost working. The problem here is that the wizard's default template renders the step's template in the middle...but your step's template is set up to produce a full html page (because it uses the master macro from main_template). If you need to customize this template, I would again recommend starting by copying the default step template from c.z.wizard (wizard-step.pt)

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)

How can I render component link field in a DWT?

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.

Resources