Copied to clipboard

Flag this post as spam?

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


  • Glen 36 posts 168 karma points
    Nov 25, 2016 @ 08:03
    Glen
    0

    How to get all tabs and properties in a single loop

    Hi,

    I have one document type with a lot of tabs and properties I wan't to iterate and display all the value, I use Template.

    @foreach(var page in CurrentPage) { // display some text or Image }

    How can I iterate the other tabs and properties?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Nov 26, 2016 @ 18:04
    Dan Diplo
    100

    I'm not quite clear what you are trying to do, but you can iterate all the properties of the current page like this:

    @{
        foreach (var prop in Model.Content.Properties)
        {
            <p>
                @prop.PropertyTypeAlias =  @prop.Value
            </p>
        }
    }
    
  • Glen 36 posts 168 karma points
    Dec 01, 2016 @ 03:48
    Glen
    0

    Hi Dan,

    Thanks for the quick reply thumbs up

    Glen

  • Roelof Nijholt 7 posts 77 karma points c-trib
    Dec 01, 2016 @ 13:00
    Roelof Nijholt
    0

    Somewhat related, I recently needed to iterate properties from specific composition tabs. This can be done like so:

    var tabs = Services.ContentTypeService.GetContentType("your_alias").CompositionPropertyGroups;
    
    tabs.ForEach(tab =>
    {
        tab.PropertyTypes.Where(prop => propRegEx.IsMatch(prop.Alias)).ForEach(prop =>
        {
            ... property logic ...
        });
    });
    

    Using propRegEx as a regular expression for matching certain tab names. Might be useful for some as well...

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Dec 01, 2016 @ 13:26
    Dan Diplo
    0

    That's handy, Roelof, but people should be aware that you shouldn't really use back-end services (like ContentTypeService) for front-end queries as it hits the DB hard. It's fine for back-office or custom stuff, of course.

  • Roelof Nijholt 7 posts 77 karma points c-trib
    Dec 01, 2016 @ 13:33
    Roelof Nijholt
    0

    Good point Dan, I guess I should have elaborated that. We use it within a custom page save event. I thought it might be handy to mention if someone was looking for properties related to tabs, as I often find useful info too here on the forum. New to sharing information here, so I will think it through better next time ;-)

  • Glen 36 posts 168 karma points
    Dec 03, 2016 @ 03:25
    Glen
    0

    Hi Roelof,

    Thank you for your suggestion really appreciated

    Glen

Please Sign in or register to post replies

Write your reply to:

Draft