Copied to clipboard

Flag this post as spam?

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


  • Snelbert 13 posts 33 karma points
    Jan 11, 2011 @ 00:18
    Snelbert
    0

    Do I need recursive?

    Hello. I admit - I have absolutely no clue what I am doing really.  First time developing in Umbraco or any CMS for that matter but here goes:

    My end game is to have a column with two images that appear by default throughout the whole site unless the end user specifically want's a different image on one page in particular.  So in conclusion I want the end user to be able to overwrite the default image.  They have no html or coding experince.

    I think I need to use a recursive field but not really sure where to include the default images?

    My template are setup as follows:

    Master

       container1

            content1

                 details.

    I have a document type and in here i have a tab that allows a user to add an image into the column.  It's called contentRight and I have the following <umbraco:Item field="contentRight" runat="server"></umbraco:Item> in the details template.  This works great.

    How and where do I set the default images? (to appear in the column if the user does not insert an image into contentRight)

    I appreciate your time for reading this.

    Thank you.

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 11, 2011 @ 00:28
    Kim Andersen
    0

    Hi Snelbert and welcome to the forum :)

    Maybe you could put the default image on the homepage(the top most node/the frontpage) of your site. Then if no other image is selcted on the childnodes, the image from the frompage will be shown.

    You can do this by setting another attribute on your umbraco:Item like this:

    <umbraco:Item field="contentRight" recursive="true" runat="server"></umbraco:Item>

    Then if you have this property on your frontpage as well, the content from the frontpage will be shown on the childnodes, unless theres some content in the field on the childnodes.

    Does that make sense? And does it solve your problem?

    /Kim A

  • Snelbert 13 posts 33 karma points
    Jan 11, 2011 @ 01:03
    Snelbert
    0

    Hi Kim, thanks for your speedy response!

    I apologise for my Micky Mouse questions.

    Does it have to be my top most template? or will any of the above ones be okay?

    Normally I would include the image like this: - 
        <img src="/images/content/midpage_ad1.jpg" alt="Corgi Membership Advertisement" width="190" height="190" class="ad1" />
         <img src="/images/content/midpage_ad2.jpg" alt="Corgi Membership Advertisement" width="190" height="190" class="ad2" />    
     

    Do I now do this in the template?

    <umbraco:Item field="contentRight" recursive="true" runat="server">
    <img src="/images/content/midpage_ad1.jpg" alt="Corgi Membership Advertisement" width="190" height="190" class="ad1" />
    <img src="/images/content/midpage_ad2.jpg" alt="Corgi Membership Advertisement" width="190" height="190" class="ad2" /> 
    </umbraco:Item>
  • sun 403 posts 395 karma points
    Jan 11, 2011 @ 02:40
    sun
    0

    Hi, Kim, can you show me more about what is recursive? how should I use it?

  • Rasmus Berntsen 215 posts 253 karma points c-trib
    Jan 11, 2011 @ 03:21
    Rasmus Berntsen
    0

    Snelbert: Don't place the images inside a Umbraco:Item, you actually just need to have the code in your template...

    Sun: Recursive="true" means that the it will look for the contentfield at the current node. If it isn't found it will look at the parent node. And the parent node. And the parent node. Until it finds a matching field. :)

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 11, 2011 @ 10:01
    Kim Andersen
    0

    Hi Snelbert.

    Don't mind the "Mickey Mouse" question - you can ask everything in here :)

    Let's take it from the top, so you know how this works:

    The "contentRight"-field, what data type is this? Is this a Richtext editor, a media picker or what is it? Let's say that it's a richtext editor. Then you can render the content from that editor in your templates by using the umbraco:Item like this:

    <umbraco:Item field="contentRight" runat="server"></umbraco:Item>

    If the richtext editor has content it will be rendered, if it hasn't got any content, then nothing will be rendered.

    Now let's say that this contentRight-field is present on all of your document types. Then you can put the two default images inside the editor on your frontpage. This will cause the images to be shown on the frontpage.

    If you want to show the two default images on the frontpage, on the subpages as well as a fallback, then you can use the code I wrote in my first post:

    <umbraco:Item field="contentRight" recursive="true" runat="server"></umbraco:Item>

    This code will show the default images selected in the contentRight from the frontpage, on the subpages - UNLESS there's something different choosen on the subpages in the contentRight field there.

    I hope this makes sense, otherwise you just ask again :)

     

    @Sun:

    Like Berntsen said, the recursive attribute are used whe you have a field on a lot of your pages, and want some kind of fallback. If the content is present on the current page, then this will be shown, if the field on the current page is empty, then the code will look for the content at the parent node. If this is empty as well, it will look at the parent's parent node etc.

    /Kim A

  • Sjors Pals 617 posts 270 karma points
    Jan 11, 2011 @ 10:11
    Sjors Pals
    0

    Funny, was not aware that Recursive="true" was an option, we did build this our selves :)

    We used something like this:

     

    [code]


            private static Node GetFeatureNode(Node node, string propertyName)
            {
                if(string.IsNullOrEmpty(node.GetProperty(propertyName).Value) && node.NodeTypeAlias != "Home")
                {
                    return GetFeatureNode(node.Parent, propertyName);
                }
                return node;
            }

    [/code]

  • Snelbert 13 posts 33 karma points
    Jan 11, 2011 @ 17:51
    Snelbert
    0

    Hi Kim


    I really appreciate your time answering my questions.  I think I have completely misunderstood where to use the field.  My contentRight is a RTE as you summise and I have included the UMbraco field as you suggest.  When I populate the content it can be seen and works as I expect.

    My problem I think is that I don't have any other document types to use the field in.  Therefore is not going to be able to find another field is it?!  I was somehow trying to use it in the template. Doh! 

     

  • Snelbert 13 posts 33 karma points
    Jan 11, 2011 @ 18:22
    Snelbert
    0

     

    I've done it!!!!


    Thanks for all your help.  Something you can count on...I'll be back!!

    Snelbert.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 11, 2011 @ 18:34
    Kim Andersen
    0

    Hi there Snelbert.

    I'm very happy that you got it solved. And actually just as happy that you'll be back to the forum :)

    If you could mark an answer as the solution in this thread it would be great, so that other users can see that this issue is no longer open.

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft