Hello All, I am currently working on an XSLT file that will be part of a package.
However when ever someone uses the macro on a page, be it via RTE or on a template, I would like it to add the necessary CSS & JS files to the page, obviously ideally in the <head> tag.
I have checked the page and they have not been added to the page, unless I specifically add runat="server" to the <head> tag.
Couple of questions then:
As a package developer I cannot ensure that everyone is using the runat="server" on the <head> tag. Is there still a way to add the CSS and JS files into the page?
Also am I using this correctly in the XSLT? Should they be in variables or params instead of just plain old value-of 's?
What version of Umbraco are you finding this error in? Looking at the code for 4.5 it should handle not having runat="server" in the head.
Alternatively you can just put the CSS/ JavaScript files out in-line on the page, this may mean you will have the same files registered multiple times (but without a runat="server" in the head you're going to hit this problem anyway)
@Casey I am not sure what you mean by processing the templates?
@Aaron I am running version 4.5.2 and this xslt is on an alt template so no currentPage context if that has anything to do with the problem. Ideally don't want to add the CSS and JS directly in the XSLT, as if the macro is used multiple times on a page then we will have duplicate calls to CSS and JS which seems unecessary.
As you are reliant on JS anyway, why not append them to the head section using javascript? There is a good example of this in the backfire package where it registers a CSS file at the point of initialisation.
Heya Matt, I will take a look at that. However I will still need to register that JS file in the XSLT and surely wouldn't that repeat the addition of the extra JS and CSS files needed?
From looking at the source of "RegisterJavaScriptFile", I would have thought that the JavaScript would be registered on the page somewhere - not necessarily in the <head> - but at least somewhere?
I think Casey might mean processing the template using a HttpModule? You could use RegEx to check for specific tags (could be the YouTube macro, or some HTML comment, or whatever) ... then inject the <script> tags into the <head>. But this isn't a very elegant solution, reminds me too much of PHP kiddie-script hacking! ;-)
IMO, the best way to handle this for Umbraco is to insert a Client Dependency control into the <head> at package install - like a Runway module. Then if the user decides to remove it, then they should be skilled enough to manually include the CSS/JS where needed? (or is that wishful thinking?)
I presume you mean if you have multiple on the page. If so, just do a check before appending (either set a bool, or just check the dom), if it's already been added, don't do it again =)
When installing the package, process the templates to verify that head has runat="server".
However, this would also require the templates to be checked with every save. (Event?)
A thought going forward: is it best practice to have runat="server" in the head, and if so, should umbraco automatically add it. I know it causes .net to manipulate things such as titles.
RegisterStyleSheetFile & RegisterJavaScriptFile without runat=server on head tag
Hello All,
I am currently working on an XSLT file that will be part of a package.
However when ever someone uses the macro on a page, be it via RTE or on a template, I would like it to add the necessary CSS & JS files to the page, obviously ideally in the <head> tag.
I have done the following in my XSLT file
I have checked the page and they have not been added to the page, unless I specifically add runat="server" to the <head> tag.
Couple of questions then:
Is there still a way to add the CSS and JS files into the page?
Should they be in variables or params instead of just plain old value-of 's?
Thanks,
Warren :)
What about processing the templates and adding it where <head> is found without the runat="server"?
What version of Umbraco are you finding this error in? Looking at the code for 4.5 it should handle not having runat="server" in the head.
Alternatively you can just put the CSS/ JavaScript files out in-line on the page, this may mean you will have the same files registered multiple times (but without a runat="server" in the head you're going to hit this problem anyway)
@Casey I am not sure what you mean by processing the templates?
@Aaron I am running version 4.5.2 and this xslt is on an alt template so no currentPage context if that has anything to do with the problem.
Ideally don't want to add the CSS and JS directly in the XSLT, as if the macro is used multiple times on a page then we will have duplicate calls to CSS and JS which seems unecessary.
Look forward to see how this can be resolved.
Cheers,
Warren :)
Hey Warren,
As you are reliant on JS anyway, why not append them to the head section using javascript? There is a good example of this in the backfire package where it registers a CSS file at the point of initialisation.
Matt
Heya Matt,
I will take a look at that. However I will still need to register that JS file in the XSLT and surely wouldn't that repeat the addition of the extra JS and CSS files needed?
Warren :)
From looking at the source of "RegisterJavaScriptFile", I would have thought that the JavaScript would be registered on the page somewhere - not necessarily in the <head> - but at least somewhere?
I think Casey might mean processing the template using a HttpModule? You could use RegEx to check for specific tags (could be the YouTube macro, or some HTML comment, or whatever) ... then inject the <script> tags into the <head>. But this isn't a very elegant solution, reminds me too much of PHP kiddie-script hacking! ;-)
IMO, the best way to handle this for Umbraco is to insert a Client Dependency control into the <head> at package install - like a Runway module. Then if the user decides to remove it, then they should be skilled enough to manually include the CSS/JS where needed? (or is that wishful thinking?)
Cheers, Lee.
Does your page have a <form runat="server"> tag on it?
Looking at MSDN their example doesn't have a runat="server" in the head..
http://msdn.microsoft.com/en-us/library/kx145dw2.aspx
Hey Warren,
I presume you mean if you have multiple on the page. If so, just do a check before appending (either set a bool, or just check the dom), if it's already been added, don't do it again =)
Matt
@Lee are you saying we should just ask the user to manually add the CSS and JS to the head section themselves?
@Matt OK that sounds like it might be the best idea for now
Will get back to you all when I have the finished solution.
Cheers,
Warren
To clarify what I was suggesting:
When installing the package, process the templates to verify that head has runat="server".
However, this would also require the templates to be checked with every save. (Event?)
A thought going forward: is it best practice to have runat="server" in the head, and if so, should umbraco automatically add it. I know it causes .net to manipulate things such as titles.
why not puting instructions at the package to manually place those scripts in the code?
Hey Sjors I am tempted to go down this route, but it is nice to think about a dummy proof option as well.
Warren :)
Well, for both something is to say. We use automatic builds, with minifying and combining css/js, and put the js at the bottom of the page...
is working on a reply...