Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Jul 15, 2015 @ 15:52
    Steve
    0

    Selecting a Folder in the Content Tree From a Macro Parameter

    I need help selecting a folder in the content tree from a macro parameter using a Razor script. What am I missing?

    I thought I could do something like:

    var selectedFolder = Parameter.selectedFolder;
    

    Here is my Razor:

    @{
        var i = 0;
    }
    @if (!String.IsNullOrEmpty(Parameter.slideFolder)) {
        var slideFolder = Parameter.slideFolder;
    
    <div class="slider">
    @foreach (var item in slideFolder.Children.Where("Visible") ){
        @item.name;
        if ( item.HasValue("image") ){
        var location = (item.titleLocation != "") ? @item.titleLocation : "top-left";
        <div class="slide" id="@i">
            <h3 class="slideTitle @location">@item.name</h3>
        @if ( item.isVideo != true) {
            <a href="@item.imageLink"><img src="@item.image" title="@item.name" alt="@item.name" /></a>
        } else {
            <a class="video" href="@item.videoURL?autoplay=1&modestBranding=0&autohide=1&showinfo=0&rel=0&fs=0&theme=light">
                <img src="/media/1362779/videooverlay.png" class="overlay" height="364" width="750" alt="Play Video for @item.name" />
                <img src="@item.image" title="@item.name" alt="@item.name" />
            </a>
        }
            <div class="caption">@item.copy</div>
        </div> 
        i++;
        }
    }
    
    </div>
    }
    

    The macro on the page won't load the script. I just get an error. I don't have anyway to turn on error reporting either.

    Also, I have all the variables declared globally, I just didn't post them.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 15, 2015 @ 18:29
    Dennis Aaen
    0

    Hi Steve,

    What version of Umbraco are you using? and next how does your first line in your Razor file looks like.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    

    or

    @inherits umbraco.MacroEngines.DynamicNodeContext
    

    Looking forward to hear from you.

    /Dennis

  • Steve 472 posts 1216 karma points
    Jul 15, 2015 @ 18:31
    Steve
    0

    I am using 6.1.6

    First lines:

    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 15, 2015 @ 19:03
    Dennis Aaen
    100

    Hi Steve,

    Okay what if you are using the follow code below will this works for you.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines
    
    @*
    Macro Parameters To Create, for this macro to work:
    Show:True   Alias:slideFolder     Name:Slide Folder ID    Type:Content Picker
    *@
    
    @{
        var i = 0;
    }
    
    @if (Parameter.slideFolder != null)
    {
         @* Get the content folder as a dynamic node *@
        var slideFolder  =  Library.NodeById(Parameter.slideFolder);
    
        foreach (var item in slideFolder.Children.Where("Visible") ){
            @item.name;
    
            if ( item.HasValue("image") ){
                var location = (item.titleLocation != "") ? @item.titleLocation : "top-left";
                    <div class="slide" id="@i">
                        <h3 class="slideTitle @location">@item.name</h3>
                            @if ( item.isVideo != true) {
                                <a href="@item.imageLink"><img src="@item.image" title="@item.name" alt="@item.name" /></a>
                            } else {
                                <a class="video" href="@item.videoURL?autoplay=1&modestBranding=0&autohide=1&showinfo=0&rel=0&fs=0&theme=light">
                                    <img src="/media/1362779/videooverlay.png" class="overlay" height="364" width="750" alt="Play Video for @item.name" />
                                    <img src="@item.image" title="@item.name" alt="@item.name" />
                                </a>
                            }
                            <div class="caption">@item.copy</div>
                        </div> 
                i++;
             }
        }
    }
    

    Hope this helps,

    /Dennis

  • Steve 472 posts 1216 karma points
    Jul 15, 2015 @ 19:06
    Steve
    0

    Will this work even if my "slideFolder" is in with the content nodes, not the media library?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 15, 2015 @ 19:10
    Dennis Aaen
    0

    Hi Steve,

    Yes it should, just to be sure that you are using Content picker as the type in the macro parameter.

    Hope this works, else I will have another look,

    /Dennis

  • Steve 472 posts 1216 karma points
    Jul 15, 2015 @ 19:11
    Steve
    0

    Well, at least the script loads now, the slideshow isn't functioning though. Thanks for getting me this far!

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 15, 2015 @ 19:16
    Dennis Aaen
    0

    Hi Steve,

    Okay that is progress. Did you remember to includes the JavaScript files. I assume that the slider that you are using are using some JavaScript.

    Else try to have a look in your browser console to see if you get some errors that can tell you why the slideshow isn't functioning.

    /Dennis

  • Steve 472 posts 1216 karma points
    Jul 15, 2015 @ 19:29
    Steve
    0

    Well, I got it working. I don't know why, but eventhough I had jquery loading in the of the template, I had to call the

  • Steve 472 posts 1216 karma points
    Jul 15, 2015 @ 19:32
    Steve
    0

    Also, when you had me change the variable for slide folder to include "Library.NodeById(Parameter.slideFolder)", was that because the parameter using a ContentPicker returns the NodeId?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 15, 2015 @ 20:34
    Dennis Aaen
    0

    Hi Steve,

    Yes the content picker returns an ID you can see the documentation here

    Try to see the Razor Macro (DynamicNode) Example

    https://our.umbraco.org/Documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Content-Picker

    That is great that you got it working, I am glad that I could help you getting there.

    I think that you should mark the question as solve so when people comes a cross this they can go directly to the solution and see what works for you.

    /Dennis

  • Steve 472 posts 1216 karma points
    Jul 15, 2015 @ 20:42
    Steve
    0

    Thanks for your help Dennis!

  • 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.

Please Sign in or register to post replies