簡體   English   中英

Razor語法中的Umbraco:Item標簽

[英]Umbraco:Item tags in Razor syntax

使用主模板,其想法是能夠從Umbraco中提取元標記和描述。 最初,主模板頁面使用的是WebForms,但是整個項目已轉換為Razor頁面。 因此,使用以下命令從Umbraco中提取了元標記和描述:

<umbraco:Item field="MetaKeywords" insertTextBefore="&lt;meta name=&quot;keywords&quot; content=&quot;" insertTextAfter="&quot; /&gt;" runat="server"></umbraco:Item>
<umbraco:Item field="MetaDescription" insertTextBefore="&lt;meta name=&quot;Description&quot; content=&quot;" insertTextAfter="&quot; /&gt;" runat="server"></umbraco:Item>

但是,在做完一些閱讀后(如果我錯了,請糾正我),umbraco item標簽不能與razor語法一起使用。 我不是專家,並且對Umbraco等非常了解。是否可以使用剃須刀頁面執行相同的功能? 在使用上述代碼的情況下,Visual Studio會說umbraco標記是無法識別的名稱空間。

如果這提供了進一步的復雜性/信息,則這是一個MVC項目。 在此先感謝您的幫助。

舊帖子,但想我會添加我為MVC找到的解決方案

https://our.umbraco.org/forum/using/ui-questions/22198-Meta-Tags


這個舊解決方案不適合您的原因是,它適用於以WebForms模式運行的網站。 由於您使用的是Umbraco 7.2.2,因此默認使用MVC,

在MVC模板中,您可以這樣稱呼它。

@Umbraco.Field("AliasOfTheField")

https://our.umbraco.org/Documentation/Reference/Mvc/views#RenderingafieldwithUmbracoHelper

因此,對於meta描述和meta關鍵字,它看起來像這樣。

@Umbraco.Field("metaDescription")
@Umbraco.Field("metaKeywords")

我已經設法使它開始工作。 對於以后遇到此問題的任何其他人,這就是我如何使其工作。 我檢查了當前頁面是否具有我正在查找的屬性,然后根據該屬性分配了關鍵字和描述。

 @if (CurrentPage.HasProperty("SeoKeywords") && CurrentPage.HasProperty("SeoDescription"))
    {
        <meta name="keywords" content="@CurrentPage.SeoKeywords" />
        <meta name="description" content="@CurrentPage.SeoDescription" />
    }

在Umbraco上,我正在使用的基礎文檔類型具有關鍵字和描述的屬性,每個屬性都有一個別名。 該別名是我正在檢查CurrentPage.HasProperty(“”)的名稱。

現在這對我有用。 希望這可以為其他任何人提供一點幫助。 也感謝“例外”澄清了原始問題。

簡單的剃須刀引擎中不支持Umbraco標簽(直到您的問題中所示為止)

基於Web的應用程序,您必須在asp.net mvc中使用htmlhelpers或html標簽。

對於前:-

@Html.TextBoxFor(),@Html.TextArea()

...或僅使用簡單的html標簽。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM