Copied to clipboard

Flag this post as spam?

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


  • Tristan 16 posts 36 karma points
    Mar 23, 2010 @ 18:12
    Tristan
    0

    Conditional statement in the master template

    Hi, I'm trying to find a way of including two specific javascript files only as part of the homepage... could you let me know what the best way to do this is?

    I sort of assume some sort of conditional statement in the header of the master template might be the best approach, whereby it only renders specific code when the pageid is the homepage one...

    Thanks!!
    Tristan

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 23, 2010 @ 18:19
    Dirk De Grave
    0

    Hi Tristan,

    Something along this lines of:

    <% if (umbraco.presentation.nodeFactory.Node.GetCurrent().Id == nodeIdOfHomePage) { %>
    ...
    <% } %>

     

    Cheers,

    /Dirk

  • Paul Blair 466 posts 731 karma points
    Mar 23, 2010 @ 20:11
    Paul Blair
    1

    Another way of achieving this (presuming you have a different template for your home page) is to create a content place holder in your master template and then in your home page template (if derived from the master) enter the javascript files.

    Here is an example from one of my sites:

        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
            <title><umbraco:Item ID="Item3" field="PageTitle" runat="server" recursive="true" /> - Mt Dobson</title>
            <link href="/css/mtdobson.css" rel="stylesheet" type="text/css" />
            <link href="/news?altTemplate=newsRSS" rel="alternate" type="application/rss+xml" title="Latest News" />
            <umbraco:Item ID="Item1" field="Keywords" insertTextBefore="&lt;meta name=&quot;keywords&quot; content=&quot;" insertTextAfter="&quot;/&gt;" recursive="true" runat="server" ></umbraco:Item>
            <umbraco:Item ID="Item2" field="Description" insertTextBefore="&lt;meta name=&quot;description&quot; content=&quot;" insertTextAfter="&quot;/&gt;" recursive="true" runat="server"></umbraco:Item>
            <asp:ContentPlaceHolder Id="ExtraHeaderItems" runat="server"></asp:ContentPlaceHolder>
        </head>

    And then in the home page template I have:

    <asp:Content ContentPlaceHolderId="ExtraHeaderItems" runat="server">
        <umbraco:Macro ID="Macro1"  Alias="HomeGallery" runat="server"></umbraco:Macro>
        <script type="text/javascript" src="/scripts/banner.js"></script>
    </asp:Content>

    Cheers

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft