Copied to clipboard

Flag this post as spam?

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


  • Jason Espin 368 posts 1335 karma points
    Apr 14, 2014 @ 15:29
    Jason Espin
    0

    Creating content that is inaccessible via link and is only accessible on other pages

    Hi all,

    I'm currently trying to create a widget of sorts that appears within the side navigation menu on my site. This widget should allow a backoffice user to enter several records for snippets of client feedback that are then used in the front office. Each time the page is loaded a random piece of client feedback will be displayed within the widget however, I do not want to allow users of the site to be able to navigate to the page on which client feedback is stored nor do I wish for this page to be displayed in any of my navigation menus. What would be the best way to approach this?

    My idea was to create a new document type under my master page that simply acts as a place holder (feedback). Underneath that I would then create a feedback item document type that would contain the feedback author, content and date. For each new piece of feedback, the back office user would simple add a new piece of content underneath the feedback content item. Once this has been done I would then be able to cycle through the ancestors of the current page which have a document type of feedback (of which there would only be one) and then I could perform a count on the number of children that this page has an random number between 1 and however many records there are and output that to screen (as I cannot see a random method in the DynamicNode cheat sheet).

    Does this sound like a good approach of is this sort of thing usually tackled in a different way?

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Apr 14, 2014 @ 15:54
    Peter Gregory
    1

    Hi Jason

    Its a fairly typical thing to do in Umbraco. From what I read your approach sounds about right. The Feedback items wont require a Template just a DocumentType and unless you provide a url to the items on the page no one will know where they actually are nor be able to navigate to them even if they did know the address of the items, it would have no template so it would render the Umbraco 404 this page is intentionally Ugly page.

    So structure wise for your doctypes I would look at something like this.

    Feedback Container (document type, no template)
    
        feedback item (document type, no template)
    

    If you want the feedback node to exist as a node inside of your main content tree make sure you add an umbracoNaviHide true false property to the feedback container to hide it.

    Then for the sidebar either create a new Partial or Macro Partial that first finds the root of the feedback. EG if the widget was on the homepage you could write a partial that looked something like this.

    @inherits UmbracoTemplatePage
    @{
        var feedbackRoot = Model.Content.DescendantsOrSelf("FeedbackContainer").FirstOrDefault();
    }
    @* list out your feedback nodes *@
    @foreach(var feedback in feedbackRoot.Children){
        <div>@feedback.Name</div>
        etc etc etc...
    
    }
    
  • Jason Espin 368 posts 1335 karma points
    Apr 14, 2014 @ 16:08
    Jason Espin
    0

    Hi Peter,

    Thanks for your response. Is there any way in which this can be modified to only output one piece of feedback at random?

    So far I have the following that I came up with myself (currently stored in a partial) but unfortunately this doesn't really seem to return anything.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
      var homepage = CurrentPage.AncestorsOrSelf(1).First();
      var feedbackOverview = homepage.feedbackOverviews.First();
      int totalFeedback = feedbackOverview.Children().Count();
      Random rnd = new Random();
      int feedbackNumber = rnd.Next(0, totalFeedback);
      var item = feedbackOverview.Next(feedbackNumber);                   
    }
    
    <span class="sideContentHeading">.Client Feedback</span>
        <div class="clientFeedback">
            <div class="clientFeedbackContent">
                @item.bodyText
            </div>
            <span class="clientFeedbackAuthor">@item.feedbackAuthor</span>
            <span class="clientFeedbackDate">@item.feedbackDate</span>
        </div>
    
  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Apr 14, 2014 @ 16:33
    Peter Gregory
    1

    Hi Jason

    Definitely. You want is the .Random() extension.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
      var homepage = Model.Content.AncestorsOrSelf(1).First();
      var feedbackOverview = homepage.feedbackOverviews.First();
    
      // the following will get you a single random item from the child collection
    
      var item = feedbackOverview.Children.Random();            
    }
    
    <span class="sideContentHeading">.Client Feedback</span>
        <div class="clientFeedback">
            <div class="clientFeedbackContent">
                @item.bodyText
            </div>
            <span class="clientFeedbackAuthor">@item.feedbackAuthor</span>
            <span class="clientFeedbackDate">@item.feedbackDate</span>
        </div>
    
  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Apr 14, 2014 @ 16:34
    Peter Gregory
    0

    I wrote a cheetsheat a while back for v6 that applies to v7 also. It would be helpful for you I think http://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets

    Peter

  • Jason Espin 368 posts 1335 karma points
    Apr 14, 2014 @ 16:38
    Jason Espin
    0

    This seems to generate the following error:

    Line 4:      var feedbackOverview = homepage.feedbackOverviews.First();
    Compiler Error Message: CS1061: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'feedbackOverviews' and no extension method 'feedbackOverviews' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?)
    

    Thanks for the link as well. I was referring to the following hence why I could not see the Random() function:

    http://our.umbraco.org/documentation/Cheatsheets/DynamicNodeRazor.pdf
    
  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Apr 14, 2014 @ 16:41
    Peter Gregory
    100

    Ahhh sorry I made a mistake in the code.

    Because you are using Dynamics line 3 and 4 need to be as you had them.

    var homepage = CurrentPage.AncestorsOrSelf(1).First();
    var feedbackOverview = homepage.feedbackOverviews.First();
    
  • Jason Espin 368 posts 1335 karma points
    Apr 14, 2014 @ 16:45
    Jason Espin
    0

    Great thanks!

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Apr 14, 2014 @ 16:48
    Peter Gregory
    0

    No problems glad I was able to help :)

Please Sign in or register to post replies

Write your reply to:

Draft