How to use property value of current page in tag query
Hello
I am attempting to create a template that displays a list of all nodes tagged with the name of the current page, e.g. display all nodes tagged Odense on a page named Odense.
If I just enter GetContentByTag("Odense") the page displays name and link of two nodes as expected.
But when I insert a variable fetching the pageTitle of the current page in place of Odense, no nodes are displayed.
So far, the template looks like this:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.List>
@using ContentModels = Umbraco.Web.PublishedContentModels;
@{
Layout = "Main.cshtml";
}
@{
var thetag = Model.Content.GetPropertyValue("pageTitle");
var result = Umbraco.TagQuery.GetContentByTag("@thetag");
}
@foreach(var item in result)
{
<p><a href="@item.Url">@item.Name</a><br/>@Umbraco.Field(item, "personFirstName")</p>
}
It might be worth checking "pageTitle" is the property you really want to retrieve. That's not a default property value in Umbraco so you would need to add it to the document type first.
If you are just after the name of the node then you could use
How to use property value of current page in tag query
Hello
I am attempting to create a template that displays a list of all nodes tagged with the name of the current page, e.g. display all nodes tagged Odense on a page named Odense.
If I just enter GetContentByTag("Odense") the page displays name and link of two nodes as expected.
But when I insert a variable fetching the pageTitle of the current page in place of Odense, no nodes are displayed.
So far, the template looks like this:
What am I doing wrong?
Probably some rookie mistake ...
Hi Jesper,
It might be worth checking "pageTitle" is the property you really want to retrieve. That's not a default property value in Umbraco so you would need to add it to the document type first.
If you are just after the name of the node then you could use
Paul
Tried with Model.Content.Name ... same result.
Weird thing is that
<p><strong>@thetag</strong></p>
renders Odense on my pagevar result = Umbraco.TagQuery.GetContentByTag("Odense");
renders a list of nodes tagged Odense.var result = Umbraco.TagQuery.GetContentByTag("@thetag");
renders nothing, not even an error message.sometimes little things make a big difference ... this combo works as intended:
basically missed the
<string>
... rookie mistake, I know :-)is working on a reply...