If I understand your question correct I have a TextPage template, for normally text pages that should contain no script tags, and then you have a contact pages also using the TextPage template, that should contain two javascripts for showing a google map on the page.
To solve this case I would make a new / specific template for the contact page, so you can add the scripts that you need for this specific page type.It can of course still inherit from your master template.
In other words: Create, a document type for each of your different page type that you have in your website. It could be news overview page, news item, text page and so on.
So if I understand it correctly, the best practise is when you have a page that is in some sort of way a little different then normal pages, you should create a new Document Type and Template?
Yes, that I what I normally do. So when I have pages that some sort of way a little different then normal page I creates a new Document Type and Template. So if I should make a news overview I would make a news overview document type and template, and the same for the news item.
So for the different page types you have in your solution, you make a document type and template.
If you have pages that use the same markup and have different fields on document type then you can choose to only create a document type, for the page, and on that document type you can set it to use the template that you already have.
I understand it completely but I have only one markup.
The @RenderBody() function on the master template inserts the html from the child template.
So if I add the script tags at the bottom of my child ( in my example contact page ) template, then they will be added at the bottom of the place where @RenderBody() is defined. But what if there is still content under this @RenderBody() function, like a footer, then the script tags will not be added at the end of the html page before the closing body tag.
Yeah I know that some people say that scripts should be loaded at the bottom of the page before the closing body tag. Back when I started developing websites, then the scripts should be loaded in the head section.
I think that you should be good, if you just place the scripts on the templates where it´s needed. So I would just add the google maps scripts on the contact template, and I think that you shold be good. It´s better than just load all the scripts on all your pages.
I have found a solution using the @Section and @RenderSection variables.
I have created a new Document Type like you suggested with a new Template where I define the @Section variable.
After that I added the @RenderSection("NameOfSectionVariable", required: false); on my Master page.
Now it adds the scripts of the child pages where @Section NameOfSectionVariable is defined.
Thanks for the intel about the requirejs, I will also look into that for better site performances.
Dynamic script tags
Hello,
since yesterday I am learning to use umbraco ( version 7 ). Before I used ASP.NET Webforms.
Now I am trying to do things in umbraco that I frequently use in my previous webforms projects.
For example:
I have a master page file which has a ContentPlaceHolder just before the closing body tag to insert script tags comming from the child webpage.
I have a child page using the masterpage file which has 2 script tags in the ContentPlaceHolder.
I have another child page using the masterpage file which doesn't contains any script tags.
How can I do this in umbraco? I have created 2 Templates:
Content:
On the master template I have added the
@RenderBody
to render the html content of the contact page.Hi Michaël and welcome to our.
If I understand your question correct I have a TextPage template, for normally text pages that should contain no script tags, and then you have a contact pages also using the TextPage template, that should contain two javascripts for showing a google map on the page.
To solve this case I would make a new / specific template for the contact page, so you can add the scripts that you need for this specific page type.It can of course still inherit from your master template.
In other words: Create, a document type for each of your different page type that you have in your website. It could be news overview page, news item, text page and so on.
Since you are new to the Umbraco 7. and mybe awhile since you last work with Umbraco I would recommned you to take a look at Umbraco.tv http://umbraco.tv/videos/umbraco-v7/implementor/, these videos are new for the Umbraaco 7. And here a some basic documentation building a website using Umbraco. http://our.umbraco.org/documentation/Using-Umbraco/Creating-Basic-Site/
Hope this helps,
/Dennis
Hello Dennis,
thanks for the information.
So if I understand it correctly, the best practise is when you have a page that is in some sort of way a little different then normal pages, you should create a new Document Type and Template?
Michael
Hi Michael,
Yes, that I what I normally do. So when I have pages that some sort of way a little different then normal page I creates a new Document Type and Template. So if I should make a news overview I would make a news overview document type and template, and the same for the news item.
So for the different page types you have in your solution, you make a document type and template.
If you have pages that use the same markup and have different fields on document type then you can choose to only create a document type, for the page, and on that document type you can set it to use the template that you already have.
Hope this helps, and make sense.
/Dennis
Hi Dennis,
I understand it completely but I have only one markup. The
@RenderBody()
function on the master template inserts the html from the child template. So if I add the script tags at the bottom of my child ( in my example contact page ) template, then they will be added at the bottom of the place where@RenderBody()
is defined. But what if there is still content under this@RenderBody()
function, like a footer, then the script tags will not be added at the end of the html page before the closing body tag.Michael
Hi Michael,
Yeah I know that some people say that scripts should be loaded at the bottom of the page before the closing body tag. Back when I started developing websites, then the scripts should be loaded in the head section.
I think that you should be good, if you just place the scripts on the templates where it´s needed. So I would just add the google maps scripts on the contact template, and I think that you shold be good. It´s better than just load all the scripts on all your pages.
If you are good in javascript you could consider take a look at the requireJS http://requirejs.org/, is a JavaScript file and module loader. With this you just require the files that are need to load the page and it only loads the javascript when it needed. Here is an article about RequireJS. http://ajaxian.com/archives/requirejs-asynchronous-javascript-loading and http://www.sitepoint.com/understanding-requirejs-for-effective-javascript-module-loading/
Hope this helps,
/Dennis
Hi Dennis,
I have found a solution using the
@Section
and@RenderSection
variables. I have created a new Document Type like you suggested with a new Template where I define the@Section
variable.After that I added the
@RenderSection("NameOfSectionVariable", required: false);
on my Master page. Now it adds the scripts of the child pages where@Section NameOfSectionVariable
is defined.Thanks for the intel about the requirejs, I will also look into that for better site performances.
Michael
Hi Michael,
Good that you find a solution. :-)
Glad that I could help you in the right direction. Happy Umbraco coding.
/Dennis
is working on a reply...