I'm using Umbraco 7.10, and I've added a Tag Cloud to my blog. I've poured over the documentation and this forum trying to find how to create links that don't use ?t=tag for example, to the tagged content but I've only been able to find a few topics that seem to relate to what I need and I'm still unsure of the direction I need to go.
I know that the tag feature in Articulate works like what I need but I already have everything I want on the site and would rather not have to use that entire package.
This works and the list of content displays on the tag page with a URL of
mysite/tag/?t=umbraco for example
<ul class="list-inline">
@foreach (TagModel tag in pTags)
{
<li><a href="/tag/[email protected]" >@tag.Text</a></li>
}
</ul>
but I would like the link to be
<a href="/tag/@tag.Text" >@tag.Text</a>
so that the URL is mysite/tag/umbraco for example and be able to display the correct content.
From what I can find I think this is about routing but I'm not sure exactly where to look in the source code to write this correctly.
If someone could point me in a very specific direction I would really appreciate it.
Sounds like this may be done by using the Content Finder (https://our.umbraco.com/documentation/reference/routing/request-pipeline/icontentfinder).
If the url starts with /tag/ then whatever will follow the url will be the tag name. Then add the tag value to the HttpContext.Items.
I recently did something for my project - here is the snippet
public class PropertyDetailsContentFinder : IContentFinder
{
public bool TryFindContent(PublishedContentRequest contentRequest)
{
try
{
if (contentRequest != null)
{
var path = contentRequest.Uri.GetAbsolutePathDecoded();
var parts = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Any() && parts.Length == 2)
{
var rootUrlName = parts.First();
// Check to see of the Url name matches the start of the requested url
if (rootUrlName.StartsWith("ENTER START OF URL HERE"))
{
// Time to get the property reference
var propertyReference = parts[1];
UmbracoContext.Current.HttpContext.Items.Add(Constants.Convention.PropertyReference, propertyReference);
// Redirect to the public profile page
contentRequest.PublishedContent = propertyDetailsPage;
}
}
}
}
catch (Exception e)
{
LogHelper.Error<PropertyDetailsContentFinder>("Error finding Property Details: ", e);
}
return contentRequest?.PublishedContent != null;
}
}
I then had a Page Controller that intercepts the request, and works with the item pushed into the HttpContext.Items.
public class PropertyDetailsPageController : RenderMvcController
{
public ActionResult PropertyDetailsPage(PropertyDetailsOverviewModel model)
{
if (!ModelState.IsValid) LogHelper.Warn<PropertyDetailsPageController>("Model Invalid for Property Details page.");
// Get the profile reference from the context
if (UmbracoContext.HttpContext.Items.Count <= 0) return CurrentTemplate(model);
var propertyReference = UmbracoContext.HttpContext.Items[Constants.Convention.PropertyReference];
if (propertyReference == null) return CurrentTemplate(model);
// DO WHAT YOU NEED TO DO TO GET THE DATA
return CurrentTemplate(model);
}
}
Hope that will start to point you in a direction to meet your needs.
Sorry about the poor code formatting - think it is an issue with the editor on this forum.
If there is a better way of doing this, then i am all ears - always happy to improve my writing.
Richard, thanks for getting me to look at the Content Finder with an extra controller.
After comparing your ideas to the way Articulate works it appears I'm going to have to work with the urlHelper Extensions and MVC routing to get exactly what I'm looking for.
Going over your code snippets got me thinking along the correct path.
URLs without query strings
I'm using Umbraco 7.10, and I've added a Tag Cloud to my blog. I've poured over the documentation and this forum trying to find how to create links that don't use ?t=tag for example, to the tagged content but I've only been able to find a few topics that seem to relate to what I need and I'm still unsure of the direction I need to go. I know that the tag feature in Articulate works like what I need but I already have everything I want on the site and would rather not have to use that entire package.
This works and the list of content displays on the tag page with a URL of mysite/tag/?t=umbraco for example
but I would like the link to be
so that the URL is mysite/tag/umbraco for example and be able to display the correct content.
From what I can find I think this is about routing but I'm not sure exactly where to look in the source code to write this correctly.
If someone could point me in a very specific direction I would really appreciate it.
Hello
Sounds like this may be done by using the Content Finder (https://our.umbraco.com/documentation/reference/routing/request-pipeline/icontentfinder).
If the url starts with /tag/ then whatever will follow the url will be the tag name. Then add the tag value to the HttpContext.Items.
I recently did something for my project - here is the snippet
public class PropertyDetailsContentFinder : IContentFinder { public bool TryFindContent(PublishedContentRequest contentRequest) { try { if (contentRequest != null) { var path = contentRequest.Uri.GetAbsolutePathDecoded(); var parts = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
I then had a Page Controller that intercepts the request, and works with the item pushed into the HttpContext.Items.
{
}
Hope that will start to point you in a direction to meet your needs.
Sorry about the poor code formatting - think it is an issue with the editor on this forum.
If there is a better way of doing this, then i am all ears - always happy to improve my writing.
Thanks so much, I'll give that a try and let you know the results.
Richard, thanks for getting me to look at the Content Finder with an extra controller.
After comparing your ideas to the way Articulate works it appears I'm going to have to work with the urlHelper Extensions and MVC routing to get exactly what I'm looking for.
Going over your code snippets got me thinking along the correct path.
you can try my code
code link
is working on a reply...