Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have been trying to us the Multiple Textbox property to list values from child pages.
I have tried different ways of doing this and by using the documentation:
but I am yet to get a resolution. Could anyone help?
Nice to see more Manchester based Umbraco devs :)
Something like this will work (replace "multiTextBoxes" with the name of your multple text box.. note how they are called "Repeatable Text Fields" in Umb 7 backend!
var childNodes = Model.Content.Children();
foreach (var curChild in childNodes)
if (curChild.HasValue("multiTextBoxes") && curChild.GetPropertyValue<string>("multiTextBoxes").Length > 0)
@foreach (var item in curChild.GetPropertyValue<string>("multiTextBoxes"))
// there is a bug where a certain republish event causes new line chars to be double output.
// check for an empty str until the bug is fixed
if (item != "")
This is great, gives me exactly what I wanted! I knew I wasn't far off.
Talking about Manchester, hope ill see you at the meet up next week.
I'll be there - come say hi!
Glad to have helped.
I am trying to get a list of distinct "keywords" (As above). I want to group all results by there keyword. As i have done with my news page (Image Below).
I have only managed at the moment to retrieve a list of Keywords but this retrieves distinct keywords on that individual page and doesn't group them from all pages, if that makes sense.
Could you possibly give me any direction please?
Not quite sure I follow what you're doing - so check my workings! This repeatable text fields field on your document is being used as a tag? What you want is to interrogate all pages and group and count the number times a particular value exists?
This is perfectly possible - I'd advice you ensure it's a cached macro (so each page load doesn't do this on each page load!) and I'd question the use of these multiple text fields.. are you happy that your editors are going to not miskey these? Wouldn't the tags field be better here?
Yeah exactly. So i currently have a list of all "Keywords" that are stored within each child page. However, i want to group all values that are the same and then count how many Child items contain that keyword. I have done this before, but the difference is, i used a drop down box value instead of the repeatable text boxes.
Just the methods i am trying doesn't seem to bring me back the correct values. I would appreciate any help :)
I do believe that the user "could" mistype but I have assurances that this will be okay for this section. I may trial the tags as i think they are represented nicer than the repeatable text boxes.
This do you?
Remember to cache this!
var rootNode = Model.Content.AncestorOrSelf(1);
Dictionary<string, int> tagsDict = new Dictionary<string, int>();
// remember to change "repeatingValues" to that of your doctype field
foreach (var descendantNode in rootNode.DescendantsOrSelf().Where(x => x.HasProperty("repeatingValues")))
var tags = descendantNode.GetPropertyValue<string>("repeatingValues").Length > 0 ? descendantNode.GetPropertyValue<string>("repeatingValues") : new string;
foreach (var curTag in tags)
// add to the dictionary
tagsDict[curTag] += 1;
foreach (var curTag in tagsDict.OrderBy(x => x.Key))
Great! After tweaking a little bit to add my styling etc, works exactly as i wanted. Thank you again for this, Steve.
Would there more than one way to do this? Or is this best practice when dealing with this kind of data?
I love this community more and more everyday!
In short - it's not really best practise - you should try to avoid traversing the entire content tree as much as possible. That's why I empathised caching.
You should definitely target that code to change from the site root node to just the root node of the News Articles or whatever contains those documents that you need to track. It might help to filter by doc type too so that fewer iterations are required.
That said - if you need this sort of functionality there is always going to be a performance cost but you mitigate it with caching / node targeting and try to keep things sensible.
I've seen sites where people traverse the entire site structure to find a "include in menu" checkbox to build their menus. This is obviously bad and more easily solved with a multi-node content picker.
Often where sites are running slowly it's too many of these sorts of things running.. but caching and being aware will keep your site snappy.
So in short - please update that code to only include the node it needs (unless it is a site wide sweep!?).
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted