Copied to clipboard

Flag this post as spam?

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


  • Garry Bain 149 posts 124 karma points
    Dec 16, 2011 @ 12:31
    Garry Bain
    0

    Can you put logic (if, else etc) into Templates?

    Hi everyone,

    I currently have a macro that is contained in my main template - however, I'd like to only display this Macro if the current page belongs to a normal "TextPage" doc type. As opposed to showing it on "News Items", "Blog Posts" and so on. Is there any sort of logic I can add to my template to say:

    if textpage { show the macro }

    Or is this done via XSLT only? If it is XSLT only - does anyone have any articles that contains any code for this?

    Cheers,
    Garry.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Dec 16, 2011 @ 12:37
    Ismail Mayat
    1

    Garry,

    If your template add the following

    <%@ Import Namespace="umbraco.presentation.nodeFactory" %>

      <script runat="server">

        Node current=null;

        void Page_Load(){

            current=Node.GetCurrent();

           

        }

      </script>

     

    then further down where you want to show the macro

     <%if(current.NodeTypeAlias=="TextPage"){%>

              <umbraco:Macro startingLevel="2" recurse="1" selectBranches="1" 

          maxMenuDepth="2" ulBaseClass="" branchClass="branch" 

          selectedClass="selected" forceNode="" expandChildren="1" 

          forceHome="0" securityTrimming="1" Alias="[COG]Navigation" runat="server">

      </umbraco:Macro>

         <%}

     

    obviously replace the macro code with your macro.

    Regards

     

    Ismail

     

     

  • Garry Bain 149 posts 124 karma points
    Dec 16, 2011 @ 15:04
    Garry Bain
    0

    unfortunately not having any luck with the above code. I have added it to the template but when I refresh the website page it is just showing the code as text in the page.  I am having to use Umbraco version 3.0 due to client development restrictions, so I wonder if the styntx is incompatible with this earlier version of umbraco?

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Dec 16, 2011 @ 16:00
    Ismail Mayat
    0

    Ah you may have a problem then as i think the old v3 templates are not .net master page templates.

  • Garry Bain 149 posts 124 karma points
    Dec 16, 2011 @ 17:55
    Garry Bain
    0

    ok thanks Ismail, we sorted it by just using some different templates for our different doc types - thanks for the help!

Please Sign in or register to post replies

Write your reply to:

Draft