Is this possible? Could it be achieved by checking the position() parameter and still get to product 3 and 4??
I know there are some 'boring' workarounds to this, but i want to create a product template on which i can check "showOnFrontpage" and then have it displayed like this (always 4 products).
If there's some chunky logic in either your product or newsletter it might be better to use XSLT templates, but hopefully this simple example points you in the right direction...
Personally, I prefer using match templates for everything that looks like a "unit" - so I'd extract the Product stuff into a separate template and do something like this:
Doh, it really was that simple.. and here i thought i should ask before trying it and potentially wasting numerous hours.....haha
Thank you both for very usefull and swift replies!
@Chriztian
By 'boring' i meant something along the lines of making 4 individual umbraco items in a new tab on the frontpage document, placing them independently of eachother with css and then adding the product intros and images in each umbraco item.
The above is much more 'fun' (helps me learn) and automated, when the data is taken from a product document template with some nifty xslt to handle the frontpage product loop :-)
Saves me from entering some data twice or in two different places.
Just wanted to let you know that both your suggestions work like a charm.
Since i haven't worked much with applying templates before it took me a little while to figure out that i should define my product variable before the template calls in Chriztians example. Great stuff :-)
But basically, XSLT works by defining templates for the elements you need to process, and then you use the apply-templates instruction to select those elements and have the processor go through them, using those templates to generate the output tree. The for-each statement is really just a shortcut to having an apply-templates instruction with a single embedded template.
When you learn how XSLT really works, you'll rarely be using for-each, though it's still needed in some specific scenarios...
For-each insert 'external' item in loop?
Hi there
Let's say that i've got 4 products nodes that i traverse and then present on my frontpage.
After product number 2 in the for-each loop i want to insert a field containing a newsletter signup. Can i do that?
Example (pretend these are container divs):
Is this possible? Could it be achieved by checking the position() parameter and still get to product 3 and 4??
I know there are some 'boring' workarounds to this, but i want to create a product template on which i can check "showOnFrontpage" and then have it displayed like this (always 4 products).
Any help or hints are much appreciated.
Hi Martin,
You could indeed do that by checking the position. Something roughly along these lines:
If there's some chunky logic in either your product or newsletter it might be better to use XSLT templates, but hopefully this simple example points you in the right direction...
Hi Martin,
I don't know about any "boring" workarounds, but it shouldn't be too hard to accomplish - you can easily do it inside the for-each, e.g.:
Personally, I prefer using match templates for everything that looks like a "unit" - so I'd extract the Product stuff into a separate template and do something like this:
/Chriztian
Doh, it really was that simple.. and here i thought i should ask before trying it and potentially wasting numerous hours.....haha
Thank you both for very usefull and swift replies!
@Chriztian
By 'boring' i meant something along the lines of making 4 individual umbraco items in a new tab on the frontpage document, placing them independently of eachother with css and then adding the product intros and images in each umbraco item.
The above is much more 'fun' (helps me learn) and automated, when the data is taken from a product document template with some nifty xslt to handle the frontpage product loop :-)
Saves me from entering some data twice or in two different places.
Just wanted to let you know that both your suggestions work like a charm.
Since i haven't worked much with applying templates before it took me a little while to figure out that i should define my product variable before the template calls in Chriztians example. Great stuff :-)
One question Chriztian.
Is the for-each an implicit part of the apply-template function?
I was wondering how your example (as I am currently using) is traversing the nodes when the for-each is not defined in the code.
Hi Martin,
Yeah, that's the huge misconception about XSLT: It's not really a programming language, so it doesn't work like you're used to :-)
I did a presentation on that at Codegarden ‘10 - slides and a link to the video here: http://pimpmyxslt.com/presentations/2010/xslt-beyond-for-each/
But basically, XSLT works by defining templates for the elements you need to process, and then you use the apply-templates instruction to select those elements and have the processor go through them, using those templates to generate the output tree. The for-each statement is really just a shortcut to having an apply-templates instruction with a single embedded template.
When you learn how XSLT really works, you'll rarely be using for-each, though it's still needed in some specific scenarios...
/Chriztian
Ah, nice.
Thank you very much for the short intro and the reference. Great stuff!
is working on a reply...