Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Schermers 112 posts 134 karma points
    Jul 12, 2012 @ 16:53
    Peter Schermers
    0

    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):

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:filesystem="urn:filesystem"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets filesystem ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <xsl:for-each select="$currentPage/fotoslider/data/item">
      <h1>test</h1>
    </xsl:for-each>

      
    </xsl:template>

    </xsl:stylesheet>

     

    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.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 12, 2012 @ 18:07
    Jeavon Leopold
    0

    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

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 08:27
    Peter Schermers
    0

    Hi Jeavon,

    Thanks for your quick reply!
    Sure, this is the configuration:

    • Umbraco 4.7.2
    • Embedded Content 1.2

    I've also added some screen grabs as you requested.
    If you need anything more, just ask ;-)

    Thanks again!

    peter

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 08:46
    Peter Schermers
    0

    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!
    p
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 13, 2012 @ 10:12
    Jeavon Leopold
    0

    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

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 10:26
    Peter Schermers
    0

    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

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 13, 2012 @ 10:27
    Jeavon Leopold
    0

    Hi Peter,

    Here you go

    @{
        var nodes @Library.NodeById(1079);
        var fotoslidernodes.fotoslider;
          foreach(dynamic item in fotoslider)
            {
            <p>@item.sliderFoto.InnerText</p>        
            }
    }  

    Regards,

    Jeavon

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 10:31
    Peter Schermers
    0

    GREAT!!! Thanks!!!!

    Everytime I use a razor I'll think of you from now on!!!

     

    :-D :-D

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 13, 2012 @ 10:32
    Jeavon Leopold
    0

    :-) Have fun!

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 10:46
    Peter Schermers
    0

    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 ;-)

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 13, 2012 @ 10:59
    Jeavon Leopold
    0

    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" />
            }
    }  

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 11:01
    Peter Schermers
    0

    Wow, I see I was getting really close myself...

    Thanks man, it works like a charm!

     

    p

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 13:35
    Peter Schermers
    0

    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?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 13, 2012 @ 14:12
    Jeavon Leopold
    0

    Works fine for me, maybe try adding some empty checks?

    e.g.

    @{
        var nodes @Library.NodeById(1049);
        var fotoslidernodes.fotoslider;
          foreach(dynamic item in fotoslider)
            {
              if (@item.sliderLink.InnerText.Length &@item.sliderFoto.InnerText.Length 0){         
                <href="@Library.NodeById(@item.sliderLink.InnerText).Url">
                      <img src="@Library.MediaById(@item.sliderFoto.InnerText).Url" width="100" height="100" />
                </a>         
            }
            }
    }  

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 14:32
    Peter Schermers
    0

    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? 

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 14:53
    Peter Schermers
    0

    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?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 13, 2012 @ 15:07
    Jeavon Leopold
    0

    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)

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 15:14
    Peter Schermers
    0

    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? 

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 13, 2012 @ 15:19
    Jeavon Leopold
    0

    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.

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 15:39
    Peter Schermers
    0

    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!

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 15:46
    Peter Schermers
    0

    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! 

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 13, 2012 @ 15:52
    Jeavon Leopold
    0

    It's strange, I have tried to break it, but I can't. Did you manage to get anything out of the debugshowtrace?

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 16:00
    Peter Schermers
    0

    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.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 13, 2012 @ 16:26
    Jeavon Leopold
    0

    Can you show me your full Razor script?

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 16:28
    Peter Schermers
    0

    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>

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 13, 2012 @ 16:35
    Jeavon Leopold
    0

    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 &@item.sliderFoto.InnerText.Length 0){         
        <li class="sliderImage">
          <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>

  • Peter Schermers 112 posts 134 karma points
    Jul 13, 2012 @ 16:41
    Peter Schermers
    0

    I am going to celebrate my weekend and holiday now, I'll get back to you later!

    Thank you so much!

Please Sign in or register to post replies

Write your reply to:

Draft