简体   繁体   中英

Kentico - Adding an anchor tag in a repeater transformation

I have an Accordion Tab repeater that I would like to add an anchor tag to each unique title within the transformation.

Here is my code:

<li>
<a href="#tab-<%# DataItemIndex+1%>-<%# Container.Parent.Parent.ClientID %>" title="<%# Eval("Title") %>">
  <span class="tab-item-title"><%# Eval("Title") %></span>
  <span class="ui-icon"></span>
  <%# String.IsNullOrEmpty(Eval<string>("MainText")) ? "" : "<div class=\"tab-item-subtitle\">" + Eval("MainText") + "</div>" %>
</a>
</li>

I tried adding:

<a id="<%# Eval("AnchorLinkName") %>" name="<%# Eval("AnchorLinkName") %>"></a>, 

but it didnt work.

No need to post this in both the DevNet and SO. The DevNet automatically includes SO posts tagged as "kentico". Reference original answer here:

https://devnet.kentico.com/questions/adding-an-anchor-tag-in-a-repeater-transformation

Typically what you do in this case is have a datasource web part on the page and specify the necessary fields (where, page types, order by, etc.). You take note of the datasources name and add that to two repeaters on the page. One repeater is or your anchor link navigation and the other is the actual content you wish to display (link to).

One thing to note, is the anchor link needs to be a URL friendly value. So something with spaces or un-encoded URL values will NOT work.

In your navigation repeater (where you link FROM), you'll need something like the following in the transformation:

<li>
    <a href="#faq-<%# Eval("DocumentID") %>"><%# Eval("DocumentName") %></a>
</li>

In your listing repeater (where you link TO), you'll need something like the following in the transformation:

<div class="faq-item" id="faq-<%# Eval("DocumentID") %>">
... your content here
</div>

Reference W3Schools Bookmarks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM