Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Duncan 7 posts 27 karma points
    Jul 23, 2012 @ 11:32
    Duncan
    0

    Please: how can I use javascript?

    Okay, I just want to use JS; no fancy user interface stuff with Umbraco of mudules and macros; just dump a heap of javascript and for it not to be eaten by TinyMCE. I don't care about style, or methodology: I would like to be able to get some javascript, that I know will work, and use it in my website (you know, mid 1990s sort of thing). 

    Does anybody know if this is possible?

    I may end up just making a website outside of umbraco, adding the javascript there, then add an iframe to my umbraco site - yes, I've worked out how to stop that wonderful TinyMCE from deleting iframes - link the iframe to the site with javascript and thereby have javascript on my umbraco website... it's not an ideal solution though!

     

    5 weeks of attempting to get a half-xslt half C# (razor?) thing with disparate elements partitioned between content and macros, with ugly handling within the CMS, to do something that would take my 10 minutes in notepad++ has left me ... slightly perplexed. 

    Thanks in advance!

  • Duncan 7 posts 27 karma points
    Jul 23, 2012 @ 11:35
    Duncan
    0

    And the edit post function in this forum is broken btw folks!

     

    Error parsing XSLT file: \xslt\forum-commentsList.xslt

     

    Tbat "take my 10 minutes" should read "take me 10 minutes" fwiw

  • Tony Bolton 83 posts 109 karma points
    Jul 23, 2012 @ 11:54
    Tony Bolton
    0

    Hi Duncan,

    Not quite sure what you mean - are you referring to the back office?

    If you're after somewhere to put the scripts, click the settings tab then right click Scripts and hit Create.  You can create your JS files in there.  Then it's just a case of adding them to the Master page(s) (aka Templates).

    As for the IFrame stuff - stick well clear of that otherwise you really are going to get in trouble later on.  If you want certain elements within content to 'do stuff' via javascript, you're best bet is to use JQuery and iterate through the elements you want to cause actions on document.load.

    If you need any more advice or want to clarify what you're trying to achieve let us know.  Oh, and stick with Umbraco - once you've got the knack it's really, really easy.

    Cheers!

    Tony

  • Duncan 7 posts 27 karma points
    Jul 23, 2012 @ 12:46
    Duncan
    0

    Thanks: but how do I add such a script to the template?

    Absolue address script src and... then... em call the script within the body of the template itself? o.O 

    Or is a sript src neccessary at all?  Because it doesn't make a lot of sense in a situation where I want some pissant code like: document.write("<p>My happy JS Test!</p>"); ... so I put it in a script, go to the template add an src to the script, then add the script within the template body where the text is supposed to appear. Three steps instead of one? :o

    Hope I never want to make a series of rollovers!

     

    Incidentally, can you add meta tags to the header section within the template?

     

  • Tony Bolton 83 posts 109 karma points
    Jul 23, 2012 @ 13:13
    Tony Bolton
    0

    Hi Duncan,

    Hmm - you're probably best off starting from the basics of .Net web-form development first and learning about Master pages and content place holders.  I suggest reading a couple of articles first before delving in.  Try http://www.w3schools.com/aspnet/aspnet_masterpages.asp and http://msdn.microsoft.com/en-us/library/wtxbf3hh(v=vs.80) are probably good starts.

    Templates in Umbraco are basically .Net master pages/content pages - it's just the terminology is different.

    In your case, you'd create a master page (I'll keep things simple, assuming you have just one master page) with all your HTML markup in it - and in the head section just add the usual <script calls to include your js files, which in umbraco start from /scripts/, so if you created a script as I mentioned before called 'myscript', then the path would be /scripts/myscript.js - assuming you're not using virtual paths of course.

    Within your master page you can also add ContentPlaceHolder elements, which are areas that sub-templates can add additional markup to.

    Finally, create your document types with properties you'd need, and set the template to the one you created.  Within that template you can then add umbraco items from the document, either directly or through macro's calling XSLT or Razor scripts.

    I'd strongly recommend subscribing to Umbraco TV - it's peanuts and by the end of it you'll have a good understanding of all the basics.

    Hope this helps!

    Tony

  • Duncan 7 posts 27 karma points
    Jul 23, 2012 @ 13:55
    Duncan
    0

    Naturally I already have a master page :D

    The above is helpful, but I'm assuming that it is therefore not possible to add JS on the fly, but that it is instead mandatory that one use script files and classes. So, for the document.write example above, I'd have to give it a class name within the script file of something like docWrite1 ....

    function docWrite1() {
    document.write("<p>My happy JS Test!</p>");
    }

    and then call it within the template after adding a script src to the header...

    docWrite1()

     

    It isn't a terribly efficient system I have to admit! However, the document.write example is obviously far more simple and short than the actual code which I want to incorporate, thereby making a separte .js file very reasonable in this circumstance.

  • Tony Bolton 83 posts 109 karma points
    Jul 23, 2012 @ 14:10
    Tony Bolton
    0

    It's certainly possible to add JS on the fly - you can do it either via an XSLT macro, Razor macro, or even inline Razor within the template itself.

    Like I said, it really depends on *exactly* what you're trying to achieve - without a proper code example it's really difficult to comment.  Some of the stuff I've done personally using JS and Umbraco is quite complex, and Umbraco has never got in the way - if anything it's aided development.

  • Duncan 7 posts 27 karma points
    Jul 23, 2012 @ 16:07
    Duncan
    0

    Okay that's working fine atm, thanks -

     

    Just wondering: the masterpage is the only place which seems to have a head section... is there anyway to have it such that a subpage alone has the script src? My js will be a slideshow, to be used only on the homepage, so will be unnecessary drag on the otherpages. 

     

    The inherited head section of the masterpage at least means I only have to write the entire website's meta tags once! :-)

  • Tony Bolton 83 posts 109 karma points
    Jul 23, 2012 @ 16:21
    Tony Bolton
    0

    Yep you got it.  To do that, create a template for the page with a slideshow, so:

    1 - In your master page you've already created, in the head section add a contentplaceholder ie:

    <asp:ContentPlaceHolder id="headerContent" runat="server" />

    2 - Save it. Now right click the master page and hit Create to create a template based on this.  Call it something like 'WithSlideshow' or whatever.

    3 - In the new template you'll see the asp:Content tag ready for you to populate?  Stick in your <script for the slideshow in there.  Now set the Document type to use this template instead and it'll have what it needs in addition to the bog standard stuff like the meta tags etc.

    There's alot more to it but that's the general jist :)

  • Sarthak 5 posts 54 karma points
    Jul 24, 2014 @ 06:41
    Sarthak
    0

    Hello all

    • I am using umbraco 4.11.6
    • I have n number of master pages in my project
    • i need to place a Javascript for a perticular page.
    • How do i acheive this.

    Thanks in advance

Please Sign in or register to post replies

Write your reply to:

Draft