I have a Document Type (Course) and Content Items (e.g. item) within the Umbraco back office, this is normally displayed using the URL like https://mysite.com/myparent/item. I use a controller CourseController through route hijacking and view Course.chtml to render this. What I'd like, is to have an alternative view TakeCourse.chtml that uses the same controller with a different action (TakeCourse) and is accessed by the URL https://mysite.com/myparent/item/takecourse.
I've spent a while looking for how to set this up but am not finding much at the moment.
Any help/advice/links anybody can be provide will be appreciated.
You may need to allow your document type to 'use' the alternative template you have created in the backoffice..
In your alternative action if you return like so:
return CurrentTemplate(yourmodel);
then the CurrentTemplate helper is clever enough to know you requested the page via the url that would trigger the altTemplate, and returns your alternative template view.
Final thing to check if it's not working, is in config/umbracosettingsconfig in the routing element to make sure altTemplates aren't turned off!
That sorted it was simply a matter that I hadn't added the alternative template to the document type in the backoffice - did that and it worked straight away!
Controllers and views
Hi,
I have a Document Type (Course) and Content Items (e.g. item) within the Umbraco back office, this is normally displayed using the URL like
https://mysite.com/myparent/item
. I use a controllerCourseController
through route hijacking and viewCourse.chtml
to render this. What I'd like, is to have an alternative viewTakeCourse.chtml
that uses the same controller with a different action (TakeCourse
) and is accessed by the URLhttps://mysite.com/myparent/item/takecourse
.I've spent a while looking for how to set this up but am not finding much at the moment.
Any help/advice/links anybody can be provide will be appreciated.
Thanks Andy
Hi Andy
It should be enough to have an Action in your controller with a name matching the name of your alternative template.
https://our.umbraco.com/documentation/reference/routing/custom-controllers#routing-via-template
You may need to allow your document type to 'use' the alternative template you have created in the backoffice..
In your alternative action if you return like so:
return CurrentTemplate(yourmodel);
then the CurrentTemplate helper is clever enough to know you requested the page via the url that would trigger the altTemplate, and returns your alternative template view.
Final thing to check if it's not working, is in config/umbracosettingsconfig in the routing element to make sure altTemplates aren't turned off!
regards
Marc
Thanks Marc,
That sorted it was simply a matter that I hadn't added the alternative template to the document type in the backoffice - did that and it worked straight away!
Thanks Andy
is working on a reply...