Okay, so I'm just starting with Umbraco and have spent almost the
entire day searching this forum for a solution for my oh so simple
problem, but I just can't get through. :-(
Here the idea:
I
installed the Embedded Content package, create a data type with my
preferred options, then went to doc types to make "Embedded Content" a
property of the master doctype "Website", using an alias called
"fotoslider" for this.
Next, as I went on to create a XSLT file
(unfortunately Razor didn't work either for me), created the macro and
embedded this in my Master template, it didn't show a thing. It did
however show something when I put something just before the
'<xsl:for-each>' code, which meant to me that there's some
noob-mistake going on in this 'for-each' thing.
Here's my XSLT code (though I would prefer using Razor, by the way):
As you can see, I neatly used my alias ('fotoslider') and still nothing shows up. I don't get an error, nothing. I hope some XSLT / Razor genius will help me fixing this ;-)
Your XSLT is 100% correct and should repeat the h1 for as many items as you have in the embedded content picker.
So, can you confirm the version of Embdedded Content & Umbraco you have and perhaps some screen grabs of the Embedded Content Picker data type setup and your property definiton on the document type?
Oh, and just to be sure I pointed everything out to you:
The hierarchy in the Content section is as follows:
Website (for all general website settings like the fotoslider I'm talking about)
Home
Producten
Contact
As you can see in my screen grabs, 'Website' isn't part of the 'Master' doctype since I wanted it to have some deviant settings for itself, not distorted by any Master.
It also doesn't include a template since it's not an existing page, of course ;-)
I hope I now told you everything you need to know!
I think I see your problem. The node/page you have created in content using the Website document type isn't actually a page (it's just a data container) and it probably doesn't sit within the site hierarchy? If so, you need to get the xml of your website node using the GetXmlNodeById method.
Something like the below, substituting the nodeid 1079 with the id of your Website content node.
Ehm... not to be unthankful but I heared that Razor is actually a lot easier to work with, and XSLT appears to be getting obsolete. Would it be too much if I asked you to create the same code in Razor for me? :-) :-) :-)
But again: thanks in advance, you've been a great help to me already!
Oh, one last step: you used my 'sliderFoto' alias, which should load all pictures loaded into the Media section with this alias, but unfortunately doesn't work. Can you fix your code at this part for me? All I get now is the ID's of the media items, while I would like the pictures themselves to load ;-)
Okay, I used your code and managed to get all other working as well, except for the pagelink I create to give the content manager the option to link an image to a certain page. This is my code (I guess it just has a small flaw, because when I split this code to test it, all parts work separated from each other but not together):
I keep getting this useless error "Error loading MacroEngine script (file: EmbeddedContent.cshtml)" Isn't there any bug mode for Razor maybe, so I can find out where it goes wrong?
Try adding ?umbDebugShowTrace=true to your url, it should give you a bit more info about the error further down (as long as you have debug enabled in web.config)
As soon as I post MORE THAN ONE entry in this 'Embedded Content' thing (like a photo, title, etc), I get the error. When I remove all entries but one it all works fine!
It's strange indeed, my entries had the next fields: photo, title, text, link. I required none of them. So when I started adding an EMPTY entry, it still worked. When I added a photo OR a title OR a text, it didn't work (same error like all day). When I added a link, it kept working. When I then added a photo, title and text (trying one by one), everything kept working.
So what am I to do now? Be happy that everything works (for now)?
Ok, I think your issue is probably happening when requests are made to the @Library functions with null values.
I added a if statement in one of my earlier posts that should solve this, you may also need to add your other properties into the if statement if they are not required.
Set up Embedded Content via XSLT
Okay, so I'm just starting with Umbraco and have spent almost the entire day searching this forum for a solution for my oh so simple problem, but I just can't get through. :-(
Here the idea:
I installed the Embedded Content package, create a data type with my preferred options, then went to doc types to make "Embedded Content" a property of the master doctype "Website", using an alias called "fotoslider" for this.
Next, as I went on to create a XSLT file (unfortunately Razor didn't work either for me), created the macro and embedded this in my Master template, it didn't show a thing. It did however show something when I put something just before the '<xsl:for-each>' code, which meant to me that there's some noob-mistake going on in this 'for-each' thing.
Here's my XSLT code (though I would prefer using Razor, by the way):
As you can see, I neatly used my alias ('fotoslider') and still nothing shows up. I don't get an error, nothing.
I hope some XSLT / Razor genius will help me fixing this ;-)
Thanks in advance.
Hi Peter,
Your XSLT is 100% correct and should repeat the h1 for as many items as you have in the embedded content picker.
So, can you confirm the version of Embdedded Content & Umbraco you have and perhaps some screen grabs of the Embedded Content Picker data type setup and your property definiton on the document type?
Regards,
Jeavon
Hi Jeavon,
Thanks for your quick reply!
Sure, this is the configuration:
I've also added some screen grabs as you requested.
If you need anything more, just ask ;-)
Thanks again!
peter
Oh, and just to be sure I pointed everything out to you:
The hierarchy in the Content section is as follows:
Hi Peter,
I think I see your problem. The node/page you have created in content using the Website document type isn't actually a page (it's just a data container) and it probably doesn't sit within the site hierarchy? If so, you need to get the xml of your website node using the GetXmlNodeById method.
Something like the below, substituting the nodeid 1079 with the id of your Website content node.
<xsl:for-each select="umbraco.library:GetXmlNodeById(1079)/fotoslider/data/item">
<h1>test</h1>
</xsl:for-each>
Let me know if this solves your problem.
Jeavon
Yes!!!
It worked!!!
Thank you so much!!!
Ehm... not to be unthankful but I heared that Razor is actually a lot easier to work with,
and XSLT appears to be getting obsolete. Would it be too much if I asked you to create the same code in Razor for me? :-) :-) :-)
But again: thanks in advance, you've been a great help to me already!
p
Hi Peter,
Here you go
@{
var nodes = @Library.NodeById(1079);
var fotoslider= nodes.fotoslider;
foreach(dynamic item in fotoslider)
{
<p>@item.sliderFoto.InnerText</p>
}
}
Regards,
Jeavon
GREAT!!! Thanks!!!!
Everytime I use a razor I'll think of you from now on!!!
:-D :-D
:-) Have fun!
Oh, one last step: you used my 'sliderFoto' alias, which should load all pictures loaded into the Media section with this alias, but unfortunately doesn't work.
Can you fix your code at this part for me? All I get now is the ID's of the media items, while I would like the pictures themselves to load ;-)
p
Something like this?
@{
var nodes = @Library.NodeById(1079);
var fotoslider= nodes.fotoslider;
foreach(dynamic item in fotoslider)
{
<img src="@Library.MediaById(@item.sliderFoto.InnerText).Url" />
}
}
Wow, I see I was getting really close myself...
Thanks man, it works like a charm!
p
Okay, I used your code and managed to get all other working as well, except for the pagelink I create to give the content manager the option to link an image to a certain page. This is my code (I guess it just has a small flaw, because when I split this code to test it, all parts work separated from each other but not together):
<a href="@Library.NodeById(@item.sliderLink.InnerText).Url">
<img src="@Library.MediaById(@item.sliderFoto.InnerText).Url" /> (this is your own piece of awesomness)
</a>
Indeed, the alias for the content picker (needed to create the link) is 'sliderLink'.
What am I doing wrong?
Works fine for me, maybe try adding some empty checks?
e.g.
@{
var nodes = @Library.NodeById(1049);
var fotoslider= nodes.fotoslider;
foreach(dynamic item in fotoslider)
{
if (@item.sliderLink.InnerText.Length > 0 && @item.sliderFoto.InnerText.Length > 0){
<a href="@Library.NodeById(@item.sliderLink.InnerText).Url">
<img src="@Library.MediaById(@item.sliderFoto.InnerText).Url" width="100" height="100" />
</a>
}
}
}
Nope, doesn't help either... :-(
I keep getting this useless error "Error loading MacroEngine script (file: EmbeddedContent.cshtml)"
Isn't there any bug mode for Razor maybe, so I can find out where it goes wrong?
Funny thing, I tried the same code for an other page, and everything worked quite well!
How can it be that such similar pages with the same codes respond so differently?
Try adding ?umbDebugShowTrace=true to your url, it should give you a bit more info about the error further down (as long as you have debug enabled in web.config)
I checked web.config and found this line:
<add key="umbracoDebugMode" value="true" />
That's what you meant, right?
Next I added your line to my URL, but nothing happens in my browser.
I'm using FireFox, where can I see the debug info you were talking about?
Thats' correct, e.g. http://localhost:40164/installing-modules.aspx?umbDebugShowTrace=true If you scroll down to the bottom of the page there should be a full Trace output. Look for the red text.
I really have no idea how I did it, but everything magically works while resetting a lot of code.
Thanks anyway, I will keep your debug tip in mind next time!
Wow, now we're getting somewhere.
As soon as I post MORE THAN ONE entry in this 'Embedded Content' thing (like a photo, title, etc), I get the error.
When I remove all entries but one it all works fine!
It's strange, I have tried to break it, but I can't. Did you manage to get anything out of the debugshowtrace?
It's strange indeed, my entries had the next fields: photo, title, text, link. I required none of them. So when I started adding an EMPTY entry, it still worked. When I added a photo OR a title OR a text, it didn't work (same error like all day). When I added a link, it kept working. When I then added a photo, title and text (trying one by one), everything kept working.
So what am I to do now? Be happy that everything works (for now)?
Like you said, it's strange.
Can you show me your full Razor script?
Sure, there you go:
<ul id="sliderContent">
@{
var nodes = @Library.NodeById(1050);
var fotoslider = nodes.fotoslider;
foreach(dynamic item in fotoslider)
{
<li class="sliderImage">
<a href="@Library.NodeById(@item.sliderLink.InnerText).Url">
<img src="@Library.MediaById(@item.sliderFoto.InnerText).Url" />
</a>
<span class="bottom">
<h1>@item.sliderTitel.InnerText</h1>
<p>
@item.sliderTekst.InnerText
</p>
</span>
</li>
}
}
<div class="clear sliderImage"></div>
</ul>
Ok, I think your issue is probably happening when requests are made to the @Library functions with null values.
I added a if statement in one of my earlier posts that should solve this, you may also need to add your other properties into the if statement if they are not required.
Try this:
<ul id="sliderContent">
@{
var nodes = @Library.NodeById(1050);
var fotoslider = nodes.fotoslider;
foreach(dynamic item in fotoslider)
{
if (@item.sliderLink.InnerText.Length > 0 && @item.sliderFoto.InnerText.Length > 0){
<li class="sliderImage">
<a href="@Library.NodeById(@item.sliderLink.InnerText).Url">
<img src="@Library.MediaById(@item.sliderFoto.InnerText).Url" />
</a>
<span class="bottom">
<h1>@item.sliderTitel.InnerText</h1>
<p>
@item.sliderTekst.InnerText
</p>
</span>
</li>
}
}
}
<div class="clear sliderImage"></div>
</ul>
I am going to celebrate my weekend and holiday now, I'll get back to you later!
Thank you so much!
is working on a reply...