Change output markup conditionally based on page data
Hi everyone!
I'm having a brain fart moment. I've done things like this in the past but for some reason I can't wrap my head around it today.
Here's what I'm doing: Pages include an optional property called pageSubheading, which is a Textstring. At the top of each page, I display the page title in an <h1> tag, but if they also include a pageSubheading, I will output that in an <h2> immediately below and wrap them both in an <hgroup> tag. Here's my XSL:
And this time the output was <hgroup><h1> Fail</h1><h2></h2></hgroup>. There was no output between the <h2> tags.
So it seems like my conditional <xsl:when> statement is wrong? Like I said, I've done this type of thing before... in fact I copied the XSL directly from an earlier project that had done something similar. So I guess I'm confused as to how to reference this properly.
This is because your initial code was using the old XML Schema (and would work with a site using that), whereas the working code use the new (as of Umbraco 4.5) XML Schema, which is much better to work with.
Change output markup conditionally based on page data
Hi everyone!
I'm having a brain fart moment. I've done things like this in the past but for some reason I can't wrap my head around it today.
Here's what I'm doing: Pages include an optional property called pageSubheading, which is a Textstring. At the top of each page, I display the page title in an <h1> tag, but if they also include a pageSubheading, I will output that in an <h2> immediately below and wrap them both in an <hgroup> tag. Here's my XSL:
W3C: The <xsl:when> element is used in conjunction with <xsl:choose> and <xsl:otherwise> to express multiple conditional tests.
Don't you need xsl:if ?
edit:
I would try to solve this by entering simple templates to the when/otherwise (just a letter),
and add each statement back line by line to see what goes wrong. Does it display any line at all or just error?
I chose to use <xsl:when> since there is no such thing as "else" in XSL.
To do some debugging, I tried this. I tested on a page that *had* some text in pageSubheading.
<hgroup><h1> Fail</h1><h2></h2></hgroup>
how's that possible, "Fail" is in your otherwise tag. while the structure is in your when.
Could it be that you must drop $currentPage(/) since you're in a template?
That's what I'm saying; I appear to be getting the opposite result? Now I've tried this...
could you try testing with $currentPage/pageSubheading ?
I've changed to this and it's now working:
Hi Alex,
This is because your initial code was using the old XML Schema (and would work with a site using that), whereas the working code use the new (as of Umbraco 4.5) XML Schema, which is much better to work with.
/Chriztian
Ah, yes, I had built the old code on a site using an earlier version of Umbraco. The site I'm building now is on 4.5.0.
Thanks!
is working on a reply...