Copied to clipboard

Flag this post as spam?

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


  • billiblu 37 posts 62 karma points
    Jul 09, 2009 @ 20:17
    billiblu
    0

    Add property with API

    Hello,

    in my website I create a News section using 2 page type: one to display the news list and one to display a single news.

    In newslist page type I create a property to define a Header Image.

    For every newspage I don not want to define a Header Image. I would like to use the property of parent page.

    The header image is displayed on "Base Master" (my base page type):

    <umbraco:Item field="headerImage" textIfEmpty="foto.jpg" runat="server"></umbraco:Item>

    I read by c# code the paret property value and I added the property on newspage.


    I don't understand where is the problem but in every newspage the header image is the default image.

    Any idea?

    Thanks,

    Billi

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jul 09, 2009 @ 20:28
    Jan Skovgaard
    0

    I am not quite sure I understand what it is you want to achieve here?

    In this line from your post it sounds like you want to inherit the image from your newslist document type

    "For every newspage I don not want to define a Header Image. I would like to use the property of parent page."

    And in this line it sounds like you don't want the newspages to inherit the image from the parent

    "I don't understand where is the problem but in every newspage the header image is the default image."

    So what is it exactly you want to achieve and what is going wrong?

    Do you want the news pages to inherit the image from the parent and is the image from the parent not shown on your news pages?

  • billiblu 37 posts 62 karma points
    Jul 09, 2009 @ 20:47
    billiblu
    0

    Thanks for replay.

    I try to explain...

    Thi is the structure:

    News list page (with headerImage Property in page template)

    |- News page 1 (without headerImage Property in page template)

    |- News page 2 (without headerImage Property in page template)

    I want inherit the headerImage property in "News page 1" and in "News page 2"... but i do not want to dispaly this property on content editor page.

    Note: the headerImageproperty is used in my basePage template with the code

    <umbraco:Item field="headerImage" textIfEmpty="foto.jpg" runat="server"></umbraco:Item>

    All my page inherit from basePage.

    With API I can read the value of headerImage property of parent and I can add a property on the fly in page_load event of basePage, but the item is render using textIfEmpty value.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jul 09, 2009 @ 20:55
    Jan Skovgaard
    100

    Try writing this in your basePage template instead

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

    I think this might do the trick for you.

  • billiblu 37 posts 62 karma points
    Jul 09, 2009 @ 21:15
    billiblu
    0

    Thanks! it Work.

    Problem solved, but... I would like to understand why, if I add a property on PageLoad it isen't correctly displayed.

    Is it correct to add the code in PageLoad of basePage?

    billi

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jul 09, 2009 @ 21:21
    Jan Skovgaard
    0

    Glad to hear you got your problem solved :)

    Well I don't think it is intended to use the API to make the recursive call when it is supported in the umbraco:item tag. Then it would not make sense.

    However it is hard for me to tell why your code does not work since I have not seen it :)

    Please mark the post that provided you with the solution so others can see the solution for the problem and jump directly to it.

    Cheers

    /Jan

  • billiblu 37 posts 62 karma points
    Jul 10, 2009 @ 01:04
    billiblu
    0

    I marked the post!

    Is true, is not necessary to use api, but I am studing Umbraco and I would understand.

    Is stupid to use this code, but for me is useful to understand the Umbraco page process.

    This is the code on the Base Page

    protected void Page_Load(object sender, EventArgs e)
    {
        int currentNodeId = umbraco.presentation.UmbracoContext.Current.PageId.Value;
        umbraco.presentation.nodeFactory.Node node = new umbraco.presentation.nodeFactory.Node(currentNodeId);

        umbraco.presentation.nodeFactory.Property pr = node.GetProperty("headerImage");

        if (pr == null)
        {
            pr = node.Parent.GetProperty("headerImage");
            if (pr != null)
                node.Properties.Add(pr);
        }
    }

    In the html of the same template (base page) I use this:

    <div id="img_testata" style="background-image:url(/media/Assets/testate/<umbraco:Item field="headerImage" recursive="true" textIfEmpty="foto.jpg" runat="server"></umbraco:Item>);"><a href="/" class="linkhome">www.asantisana.org</a></div>

    why should not work?

    Billi

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jul 10, 2009 @ 09:42
    Jan Skovgaard
    0

    Thank you.

    Well, the making of templates in Umbraco is based 100% on ASP.NET masterpages so it is not something that is specific for Umbraco.

    I am noget a hardcore .NET developer myself yet but I think that the reason why your code might not be working is because you probably need to reference different dll's to be able to use the umbraco API.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft