Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tridion 在ComponentLink中使用翻译字符串_Tridion_Tridion 2011 - Fatal编程技术网

Tridion 在ComponentLink中使用翻译字符串

Tridion 在ComponentLink中使用翻译字符串,tridion,tridion-2011,Tridion,Tridion 2011,从今天早上开始,我一直在努力解决这个问题,我知道我遗漏了一些明显的东西,但我似乎找不到 我们正在使用一个发布到服务器的XML文件,该文件包含所有标准单词的翻译,例如“阅读更多”。它是一个包含在相应出版物中本地化的组件的页面 在我们的Razor模板中,我们在一个简单的新闻摘要项目下面使用以下代码,该项目反过来链接到完整的项目 <a tridion:href="@news.ID" class="more" ><%=DefaultLabels.TranslatedTerm(((Hom

从今天早上开始,我一直在努力解决这个问题,我知道我遗漏了一些明显的东西,但我似乎找不到

我们正在使用一个发布到服务器的XML文件,该文件包含所有标准单词的翻译,例如“阅读更多”。它是一个包含在相应出版物中本地化的组件的页面

在我们的Razor模板中,我们在一个简单的新闻摘要项目下面使用以下代码,该项目反过来链接到完整的项目

<a tridion:href="@news.ID" class="more" ><%=DefaultLabels.TranslatedTerm(((HomePage)Page).Location, "read_more")%></a>
在第一个示例中,将其编写为

href
它工作得很好,代码解析成一个翻译的字符串,甚至链接到。。。只显示部件的TCM ID,而不是包含完整新闻项的正确页面

我曾尝试在Razor中创建一个函数,尝试替换linkText,尝试在模板本身中设置ComponentLink,但都无济于事。我觉得它应该只需要对这个模板的代码进行一个小的调整就可以工作,但是我没有看到它,我已经开始查看定制TBB来处理代码

有人知道如何解决这个问题吗

编辑:


Chris的答案实际上是我在这种特殊情况下寻找的答案,但我觉得我应该指出Priyank的函数也应该被视为是这样的。所以,谢谢你们两位的帮助,这让我的生活变得更轻松了

我建议不要使用默认模板解析链接,而是自己输出链接,如下所示:

<tridion:ComponentLink runat="server" PageURI="tcm:15-407-64" 
    ComponentURI="tcm:15-1475" TemplateURI="tcm:0-0-0" 
    AddAnchor="false" LinkAttributes=" class=&#34;more&#34;" 
    TextOnFail="true">
        <%=DefaultLabels.TranslatedTerm(((HomePage)Page).Location, &#34;read_more&#34;) %>
</tridionComponentLink>


<>你最好考虑输出TCDL,而不是TAGLIB/Server控件< /P> < P>我希望这个剃刀功能会对你有很大帮助。这是一个非常有用的函数,用于从组件链接或外部链接呈现链接标记

@helper RenderLink(
    dynamic link,                        // the link to render. Handles components + internal / external links
    string cssClass = null,              // optional custom CSS class
    string title = null                 // optional link text (default is the title of the component being linked to)
    ) 
{
    if(link == null) 
    {
          return;
    }

    if (title == null) 
    {   
        title = link.title;
    }

    string classAttr = string.IsNullOrEmpty(cssClass) ? "" : " class='" + cssClass + "'";
    dynamic href;
    string tridionLink = "";
    string targetAttr = "";

    if (link.Schema.Title == "External Link") 
    {
        href = link.link;
    }
    else if (link.Schema.Title == "Internal Link")
    {
        href = link.link;
        tridionLink = "tridion:";
    } 
    else 
    {
        href = link;
        tridionLink = "tridion:";
    }    

    if(link.target != null) 
    {
        targetAttr = link.target == "New window" || link.target == "Popup" ? " target='_blank'" : "";
    }    

    <a @(tridionLink)href="@href"@classAttr@targetAttr>@title</a> 
}
@helper RenderLink(
动态链接,//要呈现的链接。处理组件+内部/外部链接
字符串cssClass=null,//可选自定义CSS类
string title=null//可选链接文本(默认为链接到的组件的标题)
) 
{
if(link==null)
{
返回;
}
if(title==null)
{   
title=link.title;
}
字符串classAttr=string.IsNullOrEmpty(cssClass)?“”:“类=”+cssClass+“”;
动态href;
字符串tridionLink=“”;
字符串targetAttr=“”;
if(link.Schema.Title==“外部链接”)
{
href=link.link;
}
else if(link.Schema.Title==“内部链接”)
{
href=link.link;
tridionLink=“tridion:”;
} 
其他的
{
href=链接;
tridionLink=“tridion:”;
}    
如果(link.target!=null)
{
targetAttr=link.target==“新建窗口”| | link.target==“弹出”?“目标=”“空白”:”;
}    
}

Chris,你能解释一下为什么我不应该使用默认模板解析链接,而应该使用这种语法吗?那么输出TCDL呢?谢谢。默认的“Resolve links TBB”会找到包含TCM URI的所有链接,并将它们转换为TCDL,然后转换为REL、JSP、ASP.NET等。它通过将链接文本放置在属性中(ASP.NET控件不会执行该属性)来构建TCDL。要使代码执行,最简单的方法是标记体(而不是属性)中的链接文本(或者在您的示例中是一段代码)。我提供的代码直接引用ComponentLink服务器控件,如果该控件不在属性中,该控件将从控件体加载链接文本。
<tridion:ComponentLink runat="server" PageURI="tcm:15-407-64" 
    ComponentURI="tcm:15-1475" TemplateURI="tcm:0-0-0" 
    AddAnchor="false" LinkAttributes=" class=&#34;more&#34;" 
    TextOnFail="true">
        <%=DefaultLabels.TranslatedTerm(((HomePage)Page).Location, &#34;read_more&#34;) %>
</tridionComponentLink>
@helper RenderLink(
    dynamic link,                        // the link to render. Handles components + internal / external links
    string cssClass = null,              // optional custom CSS class
    string title = null                 // optional link text (default is the title of the component being linked to)
    ) 
{
    if(link == null) 
    {
          return;
    }

    if (title == null) 
    {   
        title = link.title;
    }

    string classAttr = string.IsNullOrEmpty(cssClass) ? "" : " class='" + cssClass + "'";
    dynamic href;
    string tridionLink = "";
    string targetAttr = "";

    if (link.Schema.Title == "External Link") 
    {
        href = link.link;
    }
    else if (link.Schema.Title == "Internal Link")
    {
        href = link.link;
        tridionLink = "tridion:";
    } 
    else 
    {
        href = link;
        tridionLink = "tridion:";
    }    

    if(link.target != null) 
    {
        targetAttr = link.target == "New window" || link.target == "Popup" ? " target='_blank'" : "";
    }    

    <a @(tridionLink)href="@href"@classAttr@targetAttr>@title</a> 
}