Copied to clipboard

Flag this post as spam?

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


  • Jonas Horsner 14 posts 37 karma points
    Jan 22, 2012 @ 01:18
    Jonas Horsner
    0

    Include HTML sections on multiple pages

    Hi, I am very new to Umbraco, and am struggling a bit :)

    I have implementet my HTML into Umbraco, and everything is working fine.

    I have a frontpage/index page, and some subpages, these does not have the same design, but one section on the pages is the same. This section I would like to be able to edit from one "file" and the include this on both templates.

    I have read quite alot howtos on how to reuse, and such - but nothing have seemed to work for me.

    Can anyone help me with this, or guide me to some tutorials on the subject?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 22, 2012 @ 04:20
    Jeroen Breuer
    0

    This blog is very old, but it explains how to use master pages: http://umbraco.com/follow-us/blog-archive/2007/12/13/dec-9-using-master-templates.aspx. That is exactly what you need. 

    This video might also help: http://umbraco.com/help-and-support/video-tutorials/umbraco-fundamentals/templating/using-master-templates/TVPlayer.

    Jeroen

  • Jonas Horsner 14 posts 37 karma points
    Jan 22, 2012 @ 11:13
    Jonas Horsner
    0

    Hi Jeroen, thank for your reply.

    But I doesn't seem to do the trick - let me elaborate what I want to do, and what I already have.

    I've already created my MasterPage doctype, and some templates.

    My structure is like this:

    Doctypes:
    Masterpage (Allowed templates: frontpage, subpage)

    Templates:
    Masterpage
    Frontpage
    Subpage

    And then I have added 2 content pages, which has the document type of Masterpage and uses either frontpage or subpage template.

    This is working fine, my masterpage is containing all the html which makes the skeleton for the page, and the other pages contains their own html. The frontpage and subpage are not the same, but they have one thing in common, a small section of html, which I would like to "include" on both pages, so I obviously don't have to edit it, for every page I create.

    What I would outside Umbraco, is just create a file which contains the html, and then include this file on all the pages which needs it. But I don't think I can do this in Umbraco, and beside it't not really what a CMS is about :)

    Hope someone can help me.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 22, 2012 @ 11:40
    Jan Skovgaard
    0

    Hi Jonas

    Maybe I'm missing something here.

    But the html you want to include on both frontpage and subpage - why is it that you don't just include it in your masterpage template? Then it's inherited to both templates. If you someday need a third template where the HTML specific for Frontpage and Subpage should not be displayed you just need to alter the Masterpage by wrapping the HTML snippet in contentplaceholder and then in the third template you just need to add an empty reference to the contenttemplateholder, which makes sure that the snippet is not rendered on this template.

    Hope this makes sense :)

    /JAN

  • Jonas Horsner 14 posts 37 karma points
    Jan 22, 2012 @ 13:34
    Jonas Horsner
    0

    Hi Jan

    It makes a little sense, my problem is, thou that the html I want to include on both pages, is in fact the same html, but it is not placed the same place on both pages.

    I don't know, if I can apply your suggestion to the problem?

    I would think, it should be possible to create an template containing the reusable html, wrap it in an contentplaceholder, and then add a content area to the places I would like the html to be added. Actually just the way, I am doing it in the masterpage.

    Don't know if any of this made sense :)

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 22, 2012 @ 13:57
    Jan Skovgaard
    0

    Hi Jonas

    In that case you just need to create two empty contentplaceholders in your master template in two different places and then just call the specific conenttemplateholder in your frontpage and the one specific for subpage in your subpage.

    That is the way to do it in asp.net masterpages :)

    /Jan

  • Jonas Horsner 14 posts 37 karma points
    Jan 22, 2012 @ 14:03
    Jonas Horsner
    0

    Hi Jan

    But if I add to empty contentplaceholder into the masterpage, wouldn't I still have to have the html in my subpage, and frontpage - or where would you call the contentplaceholder form?

    - Jonas 

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 22, 2012 @ 14:09
    Jan Skovgaard
    0

    hi Jonas

    In your mastertemplate you can easily have this (Make sure to place it where you want the content rendered on your subpages

    <asp:ContentPlaceHolder Id="header" runat="server">
            <!-- Insert default "header" markup here (Can be left empty) -->
    </asp:ContentPlaceHolder>


    <asp:ContentPlaceHolder Id="footer" runat="server">
            <!-- Insert default "header" markup here (Can be left empty) -->
    </asp:ContentPlaceHolder>

    In your frontpage template you can have this

    <asp:Content ContentPlaceHolderID="header" runat="server">
    <header>Here is my header markup</header>
    </asp:Content>

    In your subpage template you can have this
    <
    asp:Content ContentPlaceHolderID="footer" runat="server">
    <footer>Here is my header markup</footer>
    </asp:Content>

    Then the header section will only render on your frontpage and the footer section will only render on your subpage template.

    Hope this makes sense and that I'm not totally missing your point.

    /Jan

  • Jonas Horsner 14 posts 37 karma points
    Jan 22, 2012 @ 14:29
    Jonas Horsner
    0

    Hi Jan, I really appreciate your help.

    I think we are misunderstading eachother.

    I understand your above example(I think) - but lets say I use your example:

    (Header and Footer may not be the best examples, but the idea is the same.)

    Say I want the footer displayed in both templates:

    <asp:Content ContentPlaceHolderID="footer" runat="server">
    Here is my footer markup

    The above code would then appear in both templates, containing the same html.

    Therefor if I change the footer markup in subpage, it would not change in the frontpage. This is the opposite of what I want. I would like that I only had to change the html/markup one place, and then I would change on both frontpage and subpage. Kinda like if I change something in the masterpage template it would be changed on both pages.

    But my problem is that, even though the html is the same, and I could therefor place it in the masterpage - I can't, because lets say I want it displayd on the left on the frontpage and on the right on the subpage, the placement of the html would then be different.

     

     

    I could of course place the content in the masterpage and do some Javascript positioning, but I think that is a bit of a hack solution :)

    - Jonas

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 22, 2012 @ 15:51
    Jan Skovgaard
    0

    Hi Jonas

    Hmm I see.

    In that case the info should go into the master template and then you can consider doing this

    1) Create a XSLT or Razor based macro to render the footer information and make som logic where you check if it's the "frontpage" documenttype or the "subpage" document type that is the currentpage and then add a different class to your html tag containing the footer information.

    2) Create a XSLT or Razor based macro that renders you document type name as a class, which you can place on your <body> element

    Doing either of the above will make it possible for you to control the position using CSS.

    Hope it makes sense.

    /Jan

  • Jonas Horsner 14 posts 37 karma points
    Jan 22, 2012 @ 16:58
    Jonas Horsner
    0

    Hi Jan

    That was exactly what I was looking for :)

    I just made a simple razor macro, and added my html to that, and then in my frontpage and subpage template I added the macro, where I wanted it to be displayed, and it seems to work perfectly.

    Thanks for your help, now I can enjoy the rest of my weekend, or whats left of it :)

    - Jonas

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 22, 2012 @ 17:23
    Jan Skovgaard
    0

    Hi Jonas

    I'm very happy to hear that :)

    Remember to mark the issue as solved - and enjoy the rest of your weekend.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft