Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic component linking using 2 templates

Tags:

tridion

Lets say I have a component using a set schema, and this component is used with two opposing component templates, for example:

Component: Product A

Template One: Product Marketing

Template Two: Product Support

Through dynamic component linking, I want to be able to use the component's tcm uri to specify a hyperlink to where the content resides (using a dreamweaver template i.e. <a href="tcm:11-xxxx">Link text</a>)

The problem is though that if links are being generated to the wrong parts of the website I'm working on, i.e. links to product support in the product marketing section and vice versa.

I've tried setting the linking priority of the templates...both set to high....but Tridion seems to use the last template that was published for deciding where links should go.

Plus if I set one of the templates to medium and the other to high, it just takes the links to the content using the template with highest priority (i.e. all links going to product support, even in the product marketing section)

Does anyone know how to solve this? Thanks!

like image 250
Richard Read Avatar asked May 22 '12 15:05

Richard Read


People also ask

Can a component have multiple templates?

Note Although it's possible for a component to render multiple templates, we recommend using an if:true|false directive to render nested templates conditionally instead. Create multiple HTML files in the component bundle.

What can I use instead of ComponentFactoryResolver?

In Angular 13 the new API removes the need for ComponentFactoryResolver being injected into the constructor, like you did in your code. Now to dynamically create a component you have to use ViewContainerRef.

How can I use one component HTML in another component in Angular 8?

if you want to insert HTML elements or other components in a component, then you do that using the concept of content projection. In Angular, you achieve content projection using < ng-content >< /ng-content >. You can make reusable components and scalable applications by properly using content projection.


2 Answers

In addition to Chris comments, You can use the tridion:excludetemplateuri attribute to exactly control which Component Template you can link to depending on the your need either marketing or support.

in DWT.. you could use something like this.

<a tridion:href="tcm:8-299" tridion:excludetemplateuri="tcm:8-420-32">linkText</a>

Here is the link for reference

like image 116
Ram G Avatar answered Oct 12 '22 17:10

Ram G


Your issue is related to the context of the published Component Presentation. SDL Tridion resolves priorities for target CP as follows (where it only moves to the next step if there is more than one match):

  1. Finds the CP with the highest priority (You have 2 with priority high)
  2. Find the one closest to the current page, by looking in the current Structure Groups (SG), child SGs, sibling SGs etc. (You seem to have 2 here also)
  3. The final fallback scenario is that it links to the most recently published one (This is what you are seeing)

This is normally due to you having either a Dynamic Component Presentation (DCP) which is not actually on a page, or for some reason the Page ID is not set in your linking code, so then it can't calculate the location of the current CP, and as such must skip step (2) from above.

That probably does not help you solve your problem, but it does explain what you are seeing. So I can be of more help, please explain what you are publishing (is it a DCP?), and possibly look at the published code and check if a Page URI has been added to the linking code (and make sure it is not tcm:0-0-0).

like image 45
Chris Summers Avatar answered Oct 12 '22 19:10

Chris Summers