The documentation (requires login) describes you can use the tridion:anchor
attribute in your DWT Template Building Block:
<a tridion:href="@@Component.ID@@" tridion:anchor="true">blah</a>
This will output an anchor reference to your link, for Component links it will use the index (or ordinal position) of the Component on the Page you are linking to.
I think there also was a way of getting the anchor tags added to a Component Presentation but I can't seem to find out how. So simplest way of achieving that would be using this in your Page Template DWT:
<!-- TemplateBeginRepeat name="Components" -->
<a name="@@TemplateRepeatIndex + 1@@"></a>
@@RenderComponentPresentation()@@
<!-- TemplateEndRepeat -->
Update
Following HTML5 rules, you can actually also use any id
attribute with your ordinal position, and anchors will use that similar to the name
attribute of an anchor link.
So this means you could update your Page Template to look like this:
<!-- TemplateBeginRepeat name="Components" -->
<div id="@@GetOrdinalPosition(Component.ID, ComponentTemplate.ID)@@">
@@RenderComponentPresentation()@@
</div>
<!-- TemplateEndRepeat -->
Now to make it work for multiple regions, I didn't use TemplateRepeatIndex + 1
here anymore, but used a Custom Function (requires login) which gets the actual ordinal position of the Component Presentation on the Page. The code for this function would be something like this:
[TemplateCallable]
public int GetOrdinalPosition(string componentUri, string componentTemplateUri)
{
try
{
// assume we are used on a Page Template
Page page = (Page)_engine.PublishingContext.ResolvedItem.Item;
// build a Component Presentation, so we can compare that with the CPs on the Page
Component component = (Component)_engine.GetObject(componentUri);
ComponentTemplate componentTemplate = (ComponentTemplate)_engine.GetObject(componentTemplateUri);
var cp = new Tridion.ContentManager.CommunicationManagement.ComponentPresentation(component, componentTemplate);
// determine ordinal position of the given Component URI and Template URI on this Page
return page.ComponentPresentations.IndexOf(cp) + 1;
}
catch
{
return 0;
}
}