So I'm making a basic website where a small shop can post there products on their site, I created sub categories for the products, but what I want to do now is have a list of recently added products on the main stock page.
I'm really struggling to get anything to work.
I've tried going right back to the basics but I'm just getting errors and nothing rendering?
This is my current structure;
And this is the code I'm adding to my main "stock" template
Regarding your error message, it says you've already defined the variable selection... obviously the code shown is not the complete template code, so it might be used/declared already elsewhere in the template.
On to the technical part... in the assumption that "products" is the doc type alias of a product, the statement
I think we may need to see your entire view, not just this section of it. I get the feeling you've already got a variable on the same view called selection which is what you're actually looping through in your foreach statement.
Trying to add recently added section
Hello all,
So I'm making a basic website where a small shop can post there products on their site, I created sub categories for the products, but what I want to do now is have a list of recently added products on the main stock page.
I'm really struggling to get anything to work.
I've tried going right back to the basics but I'm just getting errors and nothing rendering?
This is my current structure;
And this is the code I'm adding to my main "stock" template
Ooops it might help if I added the error;
Thanks in advance,
Matt
Hi Matt,
Regarding your error message, it says you've already defined the variable selection... obviously the code shown is not the complete template code, so it might be used/declared already elsewhere in the template.
On to the technical part... in the assumption that "products" is the doc type alias of a product, the statement
will not work as product nodes in tree are NOT immediate children of your "Stock" node, but grand children, so you need to use
It'll work in your case and probably won't suffer from performance issues (if you don't have too many products/categories), but it's not the best approach, see https://our.umbraco.com/Documentation/Reference/Common-Pitfalls/#querying-with-descendants-descendantsorself
--Dirk
Hmm I thought I had this working but seems its not quite there.
This is my code, but its picking up the categories e.g Lamps,Chairs,Tables rather then the products inside of those categories.
What am I doing wrong?
Thanks
Hi Matt
Is the doctype for Lamps,Chairs,Tables by any chance "products"?
You need to put your product-doctype into the Descendants call.
Hello,
No the doctype for lamps etc is called "StockSubCat" the products doc type is called products
Which is what I'm getting confused why it doesn't seem to work?
Thanks
I think we may need to see your entire view, not just this section of it. I get the feeling you've already got a variable on the same view called
selection
which is what you're actually looping through in your foreach statement.can you try this:
is working on a reply...