I've searched through the Razor mediation documentation and SDL Tridion 2013 documentation, and can't seem to find the answer to my question.
What I'm attempting to do: Test the value of a component link in my template building block and determine if its component type is either "component" or "binary"; and then I'd like to use that information to add a target attribute depending upon the component type (component: _self, binary: _blank).
Code context:
@foreach (dynamic c in @Component.Fields.HeaderLinks)
{
if (@c.Link.ExternalLink != null && @c.Link.InternalLink == null)
{
<li><a href="@c.Link.ExternalLink" target="_blank">@c.LinkDisplayName</a></li>
}
else
{
<li><tcdl:Link type="Component" destination="@c.Link.InternalLink"
templateURI="tcm:0-0-0" linkAttributes="" textOnFail="True"
addAnchor="False">@c.LinkDisplayName</tcdl:Link></li>
}
}
I'd love to be able to get the component type, and conditionally assign the target to a string variable based upon type, something like:
if (@c.Link.InternalLink.ComponentLinkType == binary)
{
String target = "_blank";
}
or something along those lines, and then just use the variable in the linkAttributes
value within <tcdl:Link>
something like...
<tcdl:Link ... linkAttributes="@target">@c.LinkDisplayName</tcdl:Link>