Difference between partial views VS templates
# help-with-umbraco
m
I've been scratching my head with this - I have an existing site, I created a document type (with template), as a simple test, I have a single property editor (rich text editor) - I have then also added the new document type under permissions for the "page" document type - I simply want to add a paragraph along with other pages. I am able to in the content editor add the document type, I get the rich text editor, click save, publish, but if I visit the page there is nothing shown. I have in the created templated just added a SHOW ME but the template does not seem to render at all. Other content on the same page renders but this one does not. Worth noting I adopted the site so I might be doing something wrong. I noted that all of the other "sections" / "modules" dont have templates, but rather partial views. What is the difference here and if I need to use a partial view, how do I define in the document type which partial view it's intended on using?
I have made a loom video to show what I mean, I must be doing something stupid: https://www.loom.com/share/f306665df2614cc58b806451e95632d9
a
Ah few things I've noticed. - You've created a
YoutubeWithTemplate
doctype with a property - You've created a Template named
youtubewithtemplate
- you've attached these to eachother, good! - You've attached the (0:55)
Page (copy)
template to the About page. You have a Page (1:10) where you've allowed to create a subitem of type
YoutubeWithTemplate
When going to the frontend url (/about) the Page template is loaded, as that is the one attached to it. On 1:50 you're on the "This is a test' node that is based on your
YoutubeWithTemplate
document type. When you would've clicked Info there, and then the Url, the page with your
YoutubeWithTemplate
would've been loaded
In the content tree, you can see each node (item), as a seperate page. You've basically created a page called "Header" under your About page
Normally you'd add the fields you want for Header etc. to your
Page
document type. An document type is basically a blueprint of the page you want to create, so it can contain all fields you want the user to enter on that page. So if you want to add a Header field? Toss in a MediaPicker on that page, want more text? Add a RTE on it too! After this, in your template (in your case the Page template), you can get the properties of your currently used documenttype to show the information you've filled in
Example: This is my cookies page: (I've removed some content)
This is the documentType and template selected for that page
This is the documenttype itself, here I have defined the fields I want to enter in the content tree
This is my TextPage template: As you can see, I've made a partial view where I pass in the current Model (all it's propertyies), this I do so I can reuse the 'baiscpagecontent' partial on other pages. If you would replace that line with this "
Copy code
html
        <div class="page-title">
            <h1>
                <span class="page-title-first">@Model.PageTitle</span>
                <span class="page-title-second">@Model.SubTitle</span>
                <span class="page-title-third">@Model.PageSubTitle</span>
            </h1>
        </div>
    
        <div class="page-content">
            @Model.PageContent
        </div>
It would print the information on your page
I hope this makes sense a bit more now. If not I can recommend first reading a bit on : https://docs.umbraco.com/umbraco-cms/fundamentals/design/templates/ Or try installing the Umbraco Starterkit seperatly to see how its build, you can usually easily learn the basics from it
A partial view is no more then a easy (reuseable) piece of code that you can load in your template file, passing allong the properties it needs. It's not required to use, just easier to maintain if you constantly need to reuse the same piece of code
Hope this helps, if not, ask away 🙂
m
So I found the core issue
and I think this was an adopted problem
The previous developers had the following "render" view
this I assume is loaded on each page somewhere
I cant find where it's embedded as it's not in the master.chtml
but when I added an item to the switch to reference the youtuberesponsive item it works
a
Ok wow, thats quite a different approach then I see usually
m
So instead of working with it the way I believe umbraco intended, they're rolling some custom (non-dynamic) case to load a document type on each page
took me 3 days to figure this one out, happened to stumble upon the file whilst trying to find "differences" in how I am doing it vs how they did it
probably also the reason the content is structured incorrectly
a
as each page is a url by default, you could theoretically now have a
www.site.com/about-us/header
page
Well atleast you've found it, and I talked wayyyy too much 😄
m
haha I appreciate your answer here as I was about to give up
im a more seasoned PHP guy so this is mostly all new to me
and happy to learn but when things don't work the way it (or atleast the youtube videos tell me) then I have no idea how to resolve
a
No the setup you inherited is not the way umbraco sites are usually build as far as I know 😄
Welcome to the .NET club 😄
I can recommend my coworkers blog for a good read about the switch though : https://tech.ilionx.com/learning-a-new-language-its-not-as-scary-as-you-think/ She went from Symfony/Php to Umbraco/c#
j
That blog post is great, Ambert! Feel free to ping me with these gems so I can make sure I can include them in the Skrift newsletter 😄
5 Views