Have tried so many of the solutions I found by searching the forum, but no luck yet.
I have created a document-type that has a generic property called start-date and I want to make a macro for the document using that document-type that accesses start-date and more when it is finished.
My problem is that I can't find the right way to get that generic property value into my macro. Most tries have been with currentPage.
Try this simple macro - it will only do something if the currentpage is your specific Document Type and it has a value in the property - and then only if the date in that property is before "today"...
- YES, I know it's confusing, but you should really take your time to understand how these two otherwise identical pieces of code relate, and you'll be *so* much better at reading all the code samples people paste here & there...
You are right on all counts. Being php, java etc for what feels as a lifetime, this will take som getting use to, and especially the part with understading basics from your example.
I learned from this that alot changed with 4.5, and as I am on 4.01 with the system I am servicing, I need to watch out when I look for solutions. Also I see that things have been so simplyfied which I will miss out on until they update my system ;)
Again I owe you a huge beer, time and place please :D
Use of Generic properties in macro
Have tried so many of the solutions I found by searching the forum, but no luck yet.
I have created a document-type that has a generic property called start-date and I want to make a macro for the document using that document-type that accesses start-date and more when it is finished.
My problem is that I can't find the right way to get that generic property value into my macro. Most tries have been with currentPage.
Hi Nicolai,
Try this simple macro - it will only do something if the currentpage is your specific Document Type and it has a value in the property - and then only if the date in that property is before "today"...
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:umb="urn:umbraco.library" exclude-result-prefixes="umb" > <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" /> <xsl:param name="currentPage" /> <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" /> <xsl:template match="/"> <xsl:apply-templates select="$currentPage[self::DOCUMENT_TYPE_ALIAS][normalize-space(PROPERTY_ALIAS)]" /> </xsl:template> <xsl:template match="DOCUMENT_TYPE_ALIAS"> <xsl:if test="not(umb:DateGreaterThanToday(PROPERTY_ALIAS))"> <!-- Do something --> </xsl:if> </xsl:template> </xsl:stylesheet>/Chriztian
Will try that as soon as I get home again.
Will need to buy you a beer soon Chriztian, you've saved me quite a few times up till now :D
Haha :-)
You're welcome,
/Chriztian
Ok, back at my desk. I have tried the code and I must be doing something wrong.
<xsl:param name="currentPage" /> <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" /> <xsl:template match="/"> <xsl:apply-templates select="$currentPage[self::cbx-date-ctrl-page][normalize-space('start-date')]" /> </xsl:template> <xsl:template match="cbx-date-ctrl-page"> <xsl:if test="not(umb:DateGreaterThanToday('start-date'))"> <!-- Do something --> </xsl:if> </xsl:template>I have tested that $currentPage/@nodeTypeAlias gives cbx-date-ctrl-page and i can see that the dates are there when I print a $currentPage[self::*]
Hi Nicolai,
First off, if @nodeTypeAlias gives you something, you're using the "legacy XML schema" and then we need to address that.
Second, where you use start-date be sure not to wrap quotes around, 'cause then you're sending a string instead of the actual value.
So if you're actually using the new (since 4.5) XML schema this is the way to go:
<xsl:template match="/"> <xsl:apply-templates select="$currentPage[self::cbx-date-ctrl-page][normalize-space(start-date)]" /> </xsl:template> <xsl:template match="cbx-date-ctrl-page"> <xsl:if test="not(umb:DateGreaterThanToday(start-date))"> <!-- Do something --> </xsl:if> </xsl:template>- otherwise, if you're stuck on the old one - do this:
<xsl:template match="/"> <xsl:apply-templates select="$currentPage[@nodeTypeAlias = 'scbx-date-ctrl-page'][normalize-space(data[@alias = 'start-date'])]" /> </xsl:template> <xsl:template match="node[@nodeTypeAlias = 'cbx-date-ctrl-page']"> <xsl:if test="not(umb:DateGreaterThanToday(data[@alias = 'start-date']))"> <!-- Do something --> </xsl:if> </xsl:template>- YES, I know it's confusing, but you should really take your time to understand how these two otherwise identical pieces of code relate, and you'll be *so* much better at reading all the code samples people paste here & there...
/Chriztian
Hi Chriztian,
You are right on all counts. Being php, java etc for what feels as a lifetime, this will take som getting use to, and especially the part with understading basics from your example.
I learned from this that alot changed with 4.5, and as I am on 4.01 with the system I am servicing, I need to watch out when I look for solutions. Also I see that things have been so simplyfied which I will miss out on until they update my system ;)
Again I owe you a huge beer, time and place please :D
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.