Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
<!-- Register CSS & JS -->
<xsl:value-of select="umbraco.library:RegisterStyleSheetFile('uTubeCSS', '/css/YouTube.css')"/>
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:
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.
@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.
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?
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?)
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..
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 =)
@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.
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.
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...
Write your reply to:
Image will be uploaded when post is submitted