as the title says I am familiar with MVC having used various server-side frameworks at work (Java as well as ASP.NET MVC).
I cannot quite grasp Umbraco and how to go about making dynamic, "virtual" pages. eg http://mysite/products/7 while at the same time having other pages being standard Umbraco content pages. As you may have guessed, I use a single Layout file with partials for content in the menu and footer. All pages are umbraco content pages with the exception of products which
need to fetch data from a database as well as rendering some page
properties from Umbraco.
This has got to be one of the fundamental ways to make use of a CMS framework such as Umbraco but somehow I'm getting nowhere. I've looked at the documentation but it's lacking and so far my searches have resulted in... well, nothing. Thus this thread.
What are the recommendations for a scenario like this?
I've attached a file which illustrates the basic layout of the site. Let me know if you need more details in order to help me figure this out and I'll provide them.
Hi, i hope i can help in some way. As far as i understand you need to get some information from a database that gets rendered into a page along side some umbraco properties?
Why does this information need to come from the database?
You would probably have:
A View that has a partial view.
Create a custom model that will get the information from the database and include a property for a NodeID.
Instance your model and set your NodeID property (in your view)
Pass the model into the partial view.
In your partial view at the very top use: @model yournamespace.yourmodel
You can then instance a new DynamicNode passing in your node id.
DynamicNode ctxNode = new DynamicNode(@model.NodeID)
You can then get your umbraco propties from ctxNode
simply use @model. for the properties from your model.
Layout file contains header, footer and @RenderBody(), the body is an Umbraco Node, the node uses a document type to add properties, then calls a template, which is a view (MVC). Create documentType, add properties, allow the parent node to inherit, ie look at the node that will be above, then allow the node you have just created to be a child, when you create the document type, tick the box to create a matching template, this is your view. In the view or in the layout you can call a Partial which can contain properties from any document Type you have created, or can be just html, whichever is needed.
Create a document Type called Products, then one called Product where Product is a child of Products. In the Content Section, create a node Products, then create as many Product nodes underneath as you require. (In the Products template (view) you can foreach on cild elements to get all products.) To make a page of Products, call the properties from the nodes that exist underneath. You can then use the tree structure to call say an image that is on a Product Document Type (which once created and filled with information is your Body), anywhere in your structure.
Eg - you have white products, then create a Document Type of White Products, this becomes a new node at the same level as "Products", but your code in your "matching template" (view), only calls those products where the checkbox property you created on you "Product" document Type is checked to say it is white.
Hope that is not too simple, but that is my understanding of the question you are asking, in simple terms, how does the tree in the Content section relate to views and partials?
In the example you give
_Layout.cshtml
<Layout>
<div header> header text </div>
@Html.Partial("topNavigation" (the first level nodes in the tree structure), Static pages, document Types that do not need children)
@RenderBody()
@Html.Partial("footerNavigation" if menuItem is a product, then list the children of the first level node "Products")
</Layout>
Product View
@{ Layout = "_Layout.cshtml"}
@get my picture from the child node "Product"
@get the Product Title property from the child node "Product"
@get Description (as above)
@get Price (as above)
Again apologies if it appears too simple in terms of explanation, but, it took me a while to get my head around it, so hopefully you can create the picture in your mind and begin to formulate your approach.
Have not included any "real" code so as not to confuse, but hopefully the relationships between the tree structure, views and partials will be a bit clearer.
If I have missed anything, or said anything dumb, sorry, but drop a line and I will see if I can help some more.
In a couple of weeks you will leave the initial frustrations behind and appreciate just how quickly you can build a unique site with the Umbraco framework, but I will say that it can be frustrating at times, but post your question and you should be answered pretty quickly.
Sorry if I was unclear on this but I cannot have product pages in the Umbraco tree since all products are managed from another system, which the Umbraco site communicates with. You could say that the Umbraco site is the front-end of a service stack. So yes, I do need to read from a datasource of some kind. :)
For this to work I've tried setting up a custom Controller along with a custom route.
However I am not sure this is the right approach since I cannot use Umbraco context and what not. My take on it is that when you have a custom route, Umbraco itself is "side stepped" and thus no Umbraco context is created for you. I do want nice Urls like http://mysite/products/7 (where 7 easily could be replaced by a more SEO-friendly parameter)
I kinda understood what you wanted initially, but tried to explain the Umbraco/MVC part initially.
My thoughts were echoing what you are saying now, like how can Umbraco be a front-end with no products? How will the Url's be generated as you have side-stepped the Umbraco context. etc.
So my thoughts, and I would not say that they are right, but, it is a way to achieve an outcome.
If your product page, was to connect to the separate database, pull the information, cache it, then you have a front-end that you can use as a front-end. With all the Umbraco context, etc. . .(without going to the database for every page generated.)
I am not going to say that everything needs to be duplicated, but if a product document type could easily pull the new products, simply put, enter new product reference number, hit button, controller fetches data and populates, then controlled to update at a specified time, ie check for any changes every hour(?) in the original database, your additional work would just be to create a node for a new product. But it would give you the Umbraco front end operability.
Ok this is going to depend a lot on the size of the product portfolio as to how you handle it, will also depend on traffic and what speed of response is required/expected etc. .
As I mentioned, there may be a far easier way of approaching it, but what you gain on the swings you may lose on the roundabouts, as it were. My feeling is that if you side-step Umbraco, why not just build it all in MVC?
Hope it helps, but will be happy if someone can offer a better solution for you.
Why no create a dll that gets the information from the database in a model and then use that model in a partial? Simple? Like i have described above. I might be missing something here. Sorry if i am. I dont like the cacheing approach, make it strongly typed.
I would start to create the product node as a document type. Create the urls in the way you want them: /product/7.
Then use url rewriting in umbraco to transform the url to something like /products?id=7.
Create a custom controller for the product node. Inherit the controller from SurfaceController or RenderMvcController. So you have the umbraco stufff available in the controller. In the controller query your database for product information (make that in a seperate dll). Then return a view which inherits from UmbracoViewPage<T> to use your own custom model. Or use UmbracoTemplatePage and let your custom model inherit the RenderModel from Umbraco.
That's it. I think that should work and you don't need some custom routes or anything like that.
Familiar with MVC but not with Umbraco
Hey
as the title says I am familiar with MVC having used various server-side frameworks at work (Java as well as ASP.NET MVC).
I cannot quite grasp Umbraco and how to go about making dynamic, "virtual" pages. eg
http://mysite/products/7
while at the same time having other pages being standard Umbraco content pages. As you may have guessed, I use a single Layout file with partials for content in the menu and footer.
All pages are umbraco content pages with the exception of products which need to fetch data from a database as well as rendering some page properties from Umbraco.
This has got to be one of the fundamental ways to make use of a CMS framework such as Umbraco but somehow I'm getting nowhere. I've looked at the documentation but it's lacking and so far my searches have resulted in... well, nothing. Thus this thread.
What are the recommendations for a scenario like this?
I've attached a file which illustrates the basic layout of the site. Let me know if you need more details in order to help me figure this out and I'll provide them.
Thanks,
Hi, i hope i can help in some way. As far as i understand you need to get some information from a database that gets rendered into a page along side some umbraco properties?
Why does this information need to come from the database?
You would probably have:
A View that has a partial view.
Create a custom model that will get the information from the database and include a property for a NodeID.
Instance your model and set your NodeID property (in your view)
Pass the model into the partial view.
In your partial view at the very top use: @model yournamespace.yourmodel
You can then instance a new DynamicNode passing in your node id.
DynamicNode ctxNode = new DynamicNode(@model.NodeID)
You can then get your umbraco propties from ctxNode
simply use @model. for the properties from your model.
Hope this helps :)
Hi David
Two Parts - first part MVC, second Part Umbraco.
Page Layout;
Layout file contains header, footer and @RenderBody(), the body is an Umbraco Node, the node uses a document type to add properties, then calls a template, which is a view (MVC). Create documentType, add properties, allow the parent node to inherit, ie look at the node that will be above, then allow the node you have just created to be a child, when you create the document type, tick the box to create a matching template, this is your view. In the view or in the layout you can call a Partial which can contain properties from any document Type you have created, or can be just html, whichever is needed.
Create a document Type called Products, then one called Product where Product is a child of Products. In the Content Section, create a node Products, then create as many Product nodes underneath as you require. (In the Products template (view) you can foreach on cild elements to get all products.) To make a page of Products, call the properties from the nodes that exist underneath. You can then use the tree structure to call say an image that is on a Product Document Type (which once created and filled with information is your Body), anywhere in your structure.
Eg - you have white products, then create a Document Type of White Products, this becomes a new node at the same level as "Products", but your code in your "matching template" (view), only calls those products where the checkbox property you created on you "Product" document Type is checked to say it is white.
Hope that is not too simple, but that is my understanding of the question you are asking, in simple terms, how does the tree in the Content section relate to views and partials?
In the example you give
_Layout.cshtml
<Layout>
<div header> header text </div>
@Html.Partial("topNavigation" (the first level nodes in the tree structure), Static pages, document Types that do not need children)
@RenderBody()
@Html.Partial("footerNavigation" if menuItem is a product, then list the children of the first level node "Products")
</Layout>
Product View
@{ Layout = "_Layout.cshtml"}
@get my picture from the child node "Product"
@get the Product Title property from the child node "Product"
@get Description (as above)
@get Price (as above)
Again apologies if it appears too simple in terms of explanation, but, it took me a while to get my head around it, so hopefully you can create the picture in your mind and begin to formulate your approach.
Have not included any "real" code so as not to confuse, but hopefully the relationships between the tree structure, views and partials will be a bit clearer.
If I have missed anything, or said anything dumb, sorry, but drop a line and I will see if I can help some more.
In a couple of weeks you will leave the initial frustrations behind and appreciate just how quickly you can build a unique site with the Umbraco framework, but I will say that it can be frustrating at times, but post your question and you should be answered pretty quickly.
Regards
Gary
Hey guys,
thanks for your replies.
Sorry if I was unclear on this but I cannot have product pages in the Umbraco tree since all products are managed from another system, which the Umbraco site communicates with. You could say that the Umbraco site is the front-end of a service stack. So yes, I do need to read from a datasource of some kind. :)
For this to work I've tried setting up a custom Controller along with a custom route.
However I am not sure this is the right approach since I cannot use Umbraco context and what not. My take on it is that when you have a custom route, Umbraco itself is "side stepped" and thus no Umbraco context is created for you.
I do want nice Urls like http://mysite/products/7 (where 7 easily could be replaced by a more SEO-friendly parameter)
I stumpled across this thread http://our.umbraco.org/forum/developers/api-questions/38048-Umbraco-411-MVC-Custom-Routing-Content-is-null-How-can-I-load-content?p=1 but I really dislike having page node id:s hardcoded like that. Feels like there should be a better way forward.
Do you better understand what I'm trying to accomplish?
Again, thanks for the help
Hi David
Sorry for late reply.
I kinda understood what you wanted initially, but tried to explain the Umbraco/MVC part initially.
My thoughts were echoing what you are saying now, like how can Umbraco be a front-end with no products? How will the Url's be generated as you have side-stepped the Umbraco context. etc.
So my thoughts, and I would not say that they are right, but, it is a way to achieve an outcome.
If your product page, was to connect to the separate database, pull the information, cache it, then you have a front-end that you can use as a front-end. With all the Umbraco context, etc. . .(without going to the database for every page generated.)
I am not going to say that everything needs to be duplicated, but if a product document type could easily pull the new products, simply put, enter new product reference number, hit button, controller fetches data and populates, then controlled to update at a specified time, ie check for any changes every hour(?) in the original database, your additional work would just be to create a node for a new product. But it would give you the Umbraco front end operability.
Ok this is going to depend a lot on the size of the product portfolio as to how you handle it, will also depend on traffic and what speed of response is required/expected etc. .
As I mentioned, there may be a far easier way of approaching it, but what you gain on the swings you may lose on the roundabouts, as it were. My feeling is that if you side-step Umbraco, why not just build it all in MVC?
Hope it helps, but will be happy if someone can offer a better solution for you.
Best regards
Gary
Why no create a dll that gets the information from the database in a model and then use that model in a partial? Simple? Like i have described above. I might be missing something here. Sorry if i am. I dont like the cacheing approach, make it strongly typed.
I would start to create the product node as a document type. Create the urls in the way you want them: /product/7.
Then use url rewriting in umbraco to transform the url to something like /products?id=7.
Create a custom controller for the product node. Inherit the controller from SurfaceController or RenderMvcController. So you have the umbraco stufff available in the controller. In the controller query your database for product information (make that in a seperate dll). Then return a view which inherits from UmbracoViewPage<T> to use your own custom model. Or use UmbracoTemplatePage and let your custom model inherit the RenderModel from Umbraco.
That's it. I think that should work and you don't need some custom routes or anything like that.
is working on a reply...