Create a list of available courses (multinode tree picker)
Check if that list contains the current page
If it does: Write Url and Name of the school page
So far my template looks like this:
@{
var currentCourse = Model.Content.Id;
var mySchools = Model.Content.Site().Descendants("Skole").ToArray();
foreach(var item in mySchools)
{
var schoolCourses = item.GetPropertyValue<IEnumerable<IPublishedContent>>("selectedCourses").ToArray();
if (schoolCourses.Contains("CurrentCourse") == true)
{
<a href="@item.Url">@item.Name</a>
}
}
}
Umbraco does not like this line:
if (schoolCourses.Contains("CurrentCourse") == true)
I get this Compilation Error:
CS1929: 'IPublishedContent[]' does not contain a definition for 'Contains' and the best extension method overload 'Queryable.Contains<string>(IQueryable<string>, string)' requires a receiver of type 'IQueryable<string>'
the part with == true is not wrong, but you shouldn't need it anyway. Contains will return a bool you can check on.
The problem is that you are trying to check if a string is part of an IPublishedContent-Array. This won't work, you will have to check for IPublishedContent.
Try the following:
@using System.Linq;
@{
var mySchools = Model.Content.Site().Descendants("Skole");
foreach (var item in mySchools)
{
var schoolCourses = item.GetPropertyValue<IEnumerable<IPublishedContent>>("selectedCourses");
if (schoolCourses.Contains(Model.Content))
{
<a href="@item.Url">@item.Name</a>
}
}
}
Is my item on my list?
Hello I am trying the following:
So far my template looks like this:
Umbraco does not like this line:
I get this Compilation Error:
What do I need to change? Best
Hi Jesper,
try referencing namespace "System.Linq" on top of your template.
@using System.Linq;
~ Jonathan
Hi Jonathan
I added @using System.Linq; in the top of my template without much success.
Could it be my syntax with == true that is wrong?
Hi Jesper,
the part with == true is not wrong, but you shouldn't need it anyway. Contains will return a bool you can check on.
The problem is that you are trying to check if a string is part of an IPublishedContent-Array. This won't work, you will have to check for IPublishedContent.
Try the following:
Hope this helps.
~ Jonathan
Hi Jonathan
This works 100 % as I hoped it would.
As you have probably guessed I am at the early stages of learning Umbraco templating, so this was a very usefull lesson.
If this forum had a "send a nice cold IPA" function, I would definitely use it now.
All the best
is working on a reply...