Load content created in one doc type into multiple locations
Hi All,
Been struggling with a problem for a while now, sure its possibly but thing im going about it the wrong way. Probably due to my lack of "developer" knowledge.
Ive created a page which lists events (seperate doctype)
Events Page > Events
Ive got a partial view i want to use on every page on the website which lists a small selection of "featured events". This following works great on the same page the model is being used (pageEvents) but cant use it anywhere else:
Do you want the same featured events to appear on every page (is the MNTP on the events doc type) or are you wanting different events to be featured on each page (with a MNTP on every doc type)?
I would instead of getting your featured events in the partial I would suggest passing them in. I also notice you have models builder enabled so Ill write it using that :)
Edit - The reason for the error is the Page you are on is no a PageEvents but I assume a PageEvent
My example above will only work on PageEvents and its children.
If you want to use the partial else where you will need to find the PageEvents page instead of using Model.Parent as in my example. There are a few ways you can do this but for now I recommend the UmbracoHelper and TypedContentAtXPath function
@Umbraco.TypedContentAtXPath("//PageEvents")
"Queries the XML Cache for Content matching a given XPath query and returns the first match as an IPublishedContent object."
So on any page just replace
var listingPage = Model.Parent.OfType<PageEvents>();
with
var listingPage = Umbraco.TypedContentAtXPath("//PageEvents").OfType<PageEvents>();
Load content created in one doc type into multiple locations
Hi All,
Been struggling with a problem for a while now, sure its possibly but thing im going about it the wrong way. Probably due to my lack of "developer" knowledge.
Ive created a page which lists events (seperate doctype)
Events Page > Events
Ive got a partial view i want to use on every page on the website which lists a small selection of "featured events". This following works great on the same page the model is being used (pageEvents) but cant use it anywhere else:
I get the error:
Cannot bind source content type Umbraco.Web.PublishedContentModels.PageEvent to model content type Umbraco.Web.PublishedContentModels.PageEvents.
So how do i go about using it elsewhere?
Hi Ben,
Do you want the same featured events to appear on every page (is the MNTP on the events doc type) or are you wanting different events to be featured on each page (with a MNTP on every doc type)?
Kerri
The same featured events will appear on every page.
So the featured events will be only entered once using the MNTP in one place and then the hope was id use the same partial to show that on every page.
Hope that answers the question.
Hi Ben,
I would instead of getting your featured events in the partial I would suggest passing them in. I also notice you have models builder enabled so Ill write it using that :)
Edit - The reason for the error is the Page you are on is no a PageEvents but I assume a PageEvent
End Edit
Events Listing Page:
Event Page:
Featured Parital View:
Hope this helps
Matt
Thanks for the reply, cant get this to work. Probably because of my lack of programming knowledge:
Before the changes above this is what I have:
PageEvent (contains details about the event and is a page, children of PageEvents) PageEvents (lists all of its children using the below code)
Then on other pages, for example PageHome and PageInfo ive tried to use my partial @Html.Partial("_events")
which had in it the code at the start, but like you say i cant use that as im not on a PageEvents.
Not sure if that information changes anything.
My example above will only work on PageEvents and its children.
If you want to use the partial else where you will need to find the PageEvents page instead of using
Model.Parent
as in my example. There are a few ways you can do this but for now I recommend the UmbracoHelper andTypedContentAtXPath
function"Queries the XML Cache for Content matching a given XPath query and returns the first match as an IPublishedContent object."
So on any page just replace
with
Matt
is working on a reply...