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?
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...
}
@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>
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:
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?
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.
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.
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.
Hi Jason
Definitely. You want is the .Random() extension.
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
This seems to generate the following error:
Thanks for the link as well. I was referring to the following hence why I could not see the Random() function:
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.
Great thanks!
No problems glad I was able to help :)
is working on a reply...