Copied to clipboard

Flag this post as spam?

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


  • Stefan Weber 3 posts 23 karma points
    Mar 13, 2015 @ 08:00
    Stefan Weber
    0

    Retrieving all values of a field over all pages

    Dear all,

    first please excuse my bad knowledge of razor and umbraco, as both are new for me. Iam searching the forum and the documentation now for two days and couldnt find a solution for my challenge.

    I have a datatype "Software" where the content editor can add a list of benefits, which is just a list of Textstrings. Iam using the "Grid" Datatype for that.

    The result for a single software product looks like this

    • Redact PDF Documents
    • Convert PDF Documents to Word
    • ....
    Now my challenge is, that i want to create a page with a sorted list of all benefits across all software products in the hierarchy. 
    I hope one of you experts can lead me in the right direction. An example code would be very helpful.
    Thank you in advance,
    Stefan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 15, 2015 @ 09:55
    Jan Skovgaard
    0

    Hi Stefan and welcome to our :)

    Could you show what your content structure in Umbraco looks like? I assume that you have a product templates, which is being used for displaying a product and then you need to render the benefits in this template - But where are the benefits placed in your structure?

    /Jan

  • Stefan Weber 3 posts 23 karma points
    Mar 15, 2015 @ 11:32
    Stefan Weber
    0

    Thank you Jan,

    yes that is all correct. Displaying the benfits within the CurrentPage is working without problems. The Benefits are a Property within the Product Type. The data type is "Grid" (that is an additional data type package from the umbraco repository). It is just a list of textstrings.

    My challenge is, that i want to create a page with all Benefits from all content pages :-(

    Here is a screenshot of the data type iam using for the Product Benefits. 

    Best,

    Stefan

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 15, 2015 @ 11:57
    Dennis Aaen
    0

    Hi Stefan,

    What if you try something like this did it get what you want, if not could you please share a sreenshot of how your content structure in Umbraco looks like For the example you need to add the code on your template for the overview page, where all the products is children to that page.

    <div>
        @foreach(var childPage in CurrentPage.Software.Where("Visible")){
            foreach(var softwareProduct in childPage.softwareBenefit.Where("Visible")){
                <p>@softwareProduct.benefitEntry</p>
            }
        }
    </div>   

    I assme that you alias of the Software document type is software, if you have give it another alias the you need to change it so it match your case. And remember to change this softwareBenefit so it match your alias of the field on the page where you add the data.

    You can find a razor exaple on how to get data out of the U7 Data Grid different field types here: https://our.umbraco.org/projects/backoffice-extensions/u7-grid-data-type

    Hope this helps,

    /Dennis

  • Stefan Weber 3 posts 23 karma points
    Mar 16, 2015 @ 09:49
    Stefan Weber
    0

    Hi Dennis,

    my content structure looks likes this

     

     

    Within the Categories (Software, Hardware, Training and Tools) are Conent Pages of one of the following types

     

    The Product Type has a field productBenefits of Type Grid.

    I can display the benefits of the current content page. So this one is working. What i want to do is to create a separate Content Page "All Benefits", which should display all found benefits within the content hierachie.

    Example

    Produc1 has the following benefits

    * Redact a document

    * convert a pdf to word

    Product 2 has the following benefits

    * Create Mindmaps

     

    When someone clicks on the "All Benefits" page, the result should be

    * Redact a document (Product 1 Link)

    * convert a pdf to word (Product 1 Link)

    * Create Mindmaps (Product 2 Link)

    Basically i need to retrieve all values of the Benefit Entry of all content pages in the hierarchie.

    Thank you

    Stefan 

     

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

    Hi Stefan,

    Okay. So then I think that you should try something like this.

    @{
       var root = CurrentPage.AncestorOrSelf(1).Descendants("kategorien").FirstOrDefault();
      
       <div>
           @foreach(var childPage in root.Children.Where("Visible")){
                foreach(var product in childPage.productBenefits.Where("Visible")){
                    <p>@product.benefitEntry</p>
                }
            }
        </div> 
    }

    First we are find the kategorien page if there is more than one then we are taking the first one. Then we are looping through the children, to get all the categories (Software, Hardware, Training and Tools). On these pages we are taking the filed called productBenefit, and pull out the data in the benefitEntry.

    Remember to change the kategorien in this line below, so it match your propertyAlias of the page where you have the categories (Software, Hardware, Training and Tools) as children.

    var root = CurrentPage.AncestorOrSelf(1).Descendants("kategorien").FirstOrDefault();

    Hope this works for you.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft