Not having much success with rendering tags in my template.
The (very simple) template looks something like this:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = "MasterTemplate.cshtml";
}
@{
var topics = Model.Content.GetPropertyValue<string>("pageTopics");
<p>This is a page about @topics</p>
}
@if(Model.Content.GetPropertyValue<IEnumerable<string>>("pageTopics") !=null){
<ul>
@foreach(var tag in Model.Content.GetPropertyValue<IEnumerable<string>>("pageTopics")){
<li>@tag</li>
}
</ul>
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = "MasterTemplate.cshtml";
var topics = Model.Content.GetPropertyValue<string[]>("pageTopics");
}
<p>This is a page about @string.Join(", ", topics)</p>
If you insist on the tags being uppercase, i would to the following:
var topics = Model.Content.GetPropertyValue<string[]>("pageTopics").Select(x=> x.ToUpperInvariant());
In Version 8 I can not get anything to work.
To get the tags as a comma seperated string. I have tried a number of C# methods but you either get Umbraco errors or not the output you expect.
tags don't render
Not having much success with rendering tags in my template.
The (very simple) template looks something like this:
I hope to render something like
This page is about TESTING, UMBRACO, CLOUD, TAGS
But all I get is
This page is about System.String[]
What am I missing?
Hi Jesper,
Can you please give this a go.
Also make sure that your property is called pageTopics and the property is on the page that you are render in the browser.
Hope this helps,
/Dennis
Hi Dennis
When I insert this code, preview (Umbraco Canvas Designer) displays Server Error in '/' Application. Runtime Error and some more text in yellow boxes.
I have triple (actually more) checked. The property name is pageTopics, and my test page contains tags.
Tags are stored as JSON, not CSV.
I am running Umbraco Cloud.
Can you try:
}
Hi Jesper,
Here is how you should do it:
If you insist on the tags being uppercase, i would to the following:
Hi all
Suggestions from Louis and Rasmus both worked. You just resqued my whole week. Thanks.
Jesper
In Version 8 I can not get anything to work. To get the tags as a comma seperated string. I have tried a number of C# methods but you either get Umbraco errors or not the output you expect.
This returns System.String[]
This returns the same thing - System.String[]
This returns System.String[]
I just want to have a clean string of the tag.Text comma separated so I can then do a .Contains inside.
Even:
Trying to filter items based on tags with a certain text does not work.
Tags in 8 seems a bit broken.
is working on a reply...