Copied to clipboard

Flag this post as spam?

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


  • Wyverex 7 posts 27 karma points
    Jan 27, 2010 @ 10:01
    Wyverex
    0

    Avoiding redundancy in templates

    Hi all,

    I have different document types containing nested document types (e.g. a news type with nested news items, a gallery with nested gallery items etc.). Those types would have a template which calls a macro to include all the subtypes and lay them out accordingly.

    So far, so good. But now I want to include those templates in different layouts, i.e. a page may either have a single column or a two column layout, in the latter case the content would be displayed in the right column. 

    How do I set up a template hierarchy for this scenario without introducing redundancy? I thought about this a long time now but I can't come up with a solution that doesn't duplicate templates somehow.

    I guess I am missing something very obvious here.

    Thanks

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Jan 27, 2010 @ 10:16
    Sebastiaan Janssen
    1

    It sounds like you may want to create your HTML to accomodate for this, have the two columns always there, but when the left column is empty, it's width is 0 pixels. 

    You could also create the columns in an XSLT file, once again, when there is no content to display for the left column, just don't create it.

  • Wyverex 7 posts 27 karma points
    Jan 28, 2010 @ 15:13
    Wyverex
    0

    I tried to go the XSLT way, but now I am stuck on the simple fact that you cannot add ASP.NET controls inside XSLT.

    My template structure would look like this:

    Master (contains basic html frame with header and footer + placeholder for the page frame)
      +-- PageFrame (sets up the column layout somehow + must have placeholder for the specific content type)
              +-- NewsPage (html for displaying news content)
              +-- GalleryPage (html for displaying gallery content)
              +-- ....

    Now in my document type (e.g. a NewsPage document) I have a flag that indicates which column layout to use. Let's suppose when the flag is set, I want to have two columns.

    In both cases, the specific content (NewsPage, GalleryPage etc.) would be rendered inside an asp:ContentPlaceholder. When the flag is not set, the ContentPlaceholder would sit inside the single column, and when the flag is set, it would sit in the right column. Either way, the column holding the content would need a different CSS class. 

    At the moment, I don't see how I can create and configure the columns dynamically and still add the ContentPlaceholder. What am I missing here? Or should I take a completely different approach?

  • Seth Niemuth 275 posts 397 karma points
    Jan 28, 2010 @ 15:38
    Seth Niemuth
    0

    Could you not just have something like this for your page frame:

    <table>

    <tr>

    Call Macro for two column (then in the macro it will put out <td> your left column info</td> if there is supposed to be 2 columns and output nothing if there isn't)

    <td>

    <asp:ContentPlaceholder ... />

    </td>

    </tr>

    </table>

    You could also do it with divs as well.

  • Wyverex 7 posts 27 karma points
    Jan 28, 2010 @ 16:07
    Wyverex
    0

    That was my first thought, too. But the <td> (in your case, I'm using <div>s) holding the ContentPlaceholder needs to have a different CSS class as well. But I cannot include just the opening tag in the macro since missing closing tags throw an error when trying to use the xslt. And I can't include the whole tag either because I cannot create an asp: tag inside xslt.

    But I'm currently experimenting with adding conditional logic into the template itself. Maybe that's the path to take. I'll keep you posted.

  • Seth Niemuth 275 posts 397 karma points
    Jan 28, 2010 @ 16:15
    Seth Niemuth
    0

    You can put this into your XSLT and save it and it will come out as html:

    <xsl:text disable-output-escaping="yes">

    &lt;div class="twoColumn"> </xsl:text>

  • Wyverex 7 posts 27 karma points
    Jan 28, 2010 @ 16:40
    Wyverex
    0

    That was the missing piece. Works like a charm now.

    Thank you!

Please Sign in or register to post replies

Write your reply to:

Draft