Copied to clipboard

Flag this post as spam?

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


  • Sharmarke Hujale 103 posts 346 karma points
    Dec 03, 2016 @ 21:36
    Sharmarke Hujale
    0

    Getting information from one page and display it on another, help!

    Hi guys!

    I ran into a problem. What I'm talking about is two pages, the home page and a service page.

    I've 6 services like this displayed on my service site: enter image description here

    And the code is like this ex.:

      <!-- Third service -->
            <div class="col-md-4 col-sm-12 wow fadeInUp icon-service-box">
                <img class="service-icon" src="~/Images/grafisk-design.svg" />
                @if (CurrentPage.HasValue("serviceTitle3"))
                {
                    <h3 class="service-title">@Umbraco.Field("serviceTitle3")</h3>
                }
                @if (CurrentPage.HasValue("serviceContent3"))
                {
                    <p class="service-content">@Umbraco.Field("serviceContent3")</p>
                }
            </div>
    

    That's easy for me to use since I made the properties on the service document type, therefore I can use just the @Umbraco.Field

    My problem is, that I want also the 6 services to display on my home page, but I'm not sure how to achieve that. How do I get access and use my properties from the service document type

    So I can get it displayed on the home page. And since they're not child items I can't use method like this one:

    var blog = Model.Content.AncestorOrSelf(1).Descendants("blog").FirstOrDefault();
    

    I hope my question was understandable

    Thanks in advance!

    //Sharmarke

  • Yasir Butt 161 posts 371 karma points
    Dec 03, 2016 @ 21:45
    Yasir Butt
    0

    Hi,

    can u please share ur content tree structure? then it will be easy to help you.

    Yasir

  • Sharmarke Hujale 103 posts 346 karma points
    Dec 03, 2016 @ 22:06
    Sharmarke Hujale
    0

    Yes of course - here it is:

    enter image description here

    The one named "ydelser" is the service node

  • Yasir Butt 161 posts 371 karma points
    Dec 03, 2016 @ 22:40
    Yasir Butt
    0

    Hi,

    You can get these as you given the code example of blog. i am not seeing any problem to get service node. As you are already on home page so you can use directly descendants.

    var servicePage = Model.Content.Descendants("yourservice").FirstOrDefault();
    

    It can also solve in another way like

    1. Create a property named service page at home page with use of content picker control.
    2. Get the value of service page like

      var servicePage = Umbraco.TypedContent(Model.Content.GetPropertyValue

    @servicePage.GetPropertyValue("yourproperty")

    Another thing i have noticed that you have created the six property like "serviceTitle1", "serviceTitle2" as you mentioned.

    What happened if customer need 2 more services in future so you will create the 2 more properties. right? then customer has no control over it but dependent on you.

    I suggest that you many use Archetype OR create service page where each page represent single service. then customer can create as many services they want.

    Hopefully it work for you.

    Yasir

  • Sharmarke Hujale 103 posts 346 karma points
    Dec 03, 2016 @ 22:54
    Sharmarke Hujale
    0

    Hi Yasir,

    I know about the names (service 1, service 2 etc.). It's not for a customer, but for myself so it's not a big problem there.

    But how can use this one:

     var servicePage = Model.Content.Descendants("yourservice").FirstOrDefault();
    

    When I don't have any descendants. I've created a property named services on my service page.

    So do you suggest I should solve the problem with the use of content picker?

  • Yasir Butt 161 posts 371 karma points
    Dec 03, 2016 @ 23:01
    Yasir Butt
    0

    Hi,

    You are on Home page so Ydelser er the child of home. so you can access it using Descendants OR Descendant

    How can you say that it is not the children of home? Please try with descendants first.

    Other one was the alternative solution using content picker.

    its upto you which one would you like to use.

    Yasir

  • Sharmarke Hujale 103 posts 346 karma points
    Dec 04, 2016 @ 13:35
    Sharmarke Hujale
    0

    Hi Yasir,

    You were right - I wasn't thinking right

    I did this:

    var ydelser = Model.Content.Descendants("ydelser").FirstOrDefault();
    

    But I got an error when I did this:

     @if (ydelser.HasValue("serviceTitle3"))
                {
                    <h3 class="service-title">@ydelser.serviceTitle3</h3>
                }
    
  • Sharmarke Hujale 103 posts 346 karma points
    Dec 04, 2016 @ 13:50
    Sharmarke Hujale
    0

    It gives me this error:

    CS1061: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'serviceTitle3' and no extension method 'serviceTitle3' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?

  • Yasir Butt 161 posts 371 karma points
    Dec 04, 2016 @ 13:52
    Yasir Butt
    0

    is "ydelser" your document type alias?

    Please double check your document type alias

    Yasir

  • Sharmarke Hujale 103 posts 346 karma points
    Dec 04, 2016 @ 13:55
    Sharmarke Hujale
    0

    Yes, it is my document type alias

  • Yasir Butt 161 posts 371 karma points
    Dec 04, 2016 @ 14:04
    Yasir Butt
    0

    hmm!

    I am assuming that your code is on home page. right?

    can you please also share the screen of your document type ydelser?

  • Sharmarke Hujale 103 posts 346 karma points
    Dec 04, 2016 @ 14:13
    Sharmarke Hujale
    0

    Yes, the code is on my home page...

    Here it is:

    enter image description here

  • Yasir Butt 161 posts 371 karma points
    Dec 04, 2016 @ 14:43
    Yasir Butt
    0

    its little strange. looks like every thing is correct

    can you check that what is coming in your variable ydelser?

    either you may try

    var ydelser = Model.Content.Descendant("ydelser")
    

    lets check that is it iPublishedContent?

  • Sharmarke Hujale 103 posts 346 karma points
    Dec 04, 2016 @ 14:55
    Sharmarke Hujale
    0

    I still get the same error

  • Yasir Butt 161 posts 371 karma points
    Dec 04, 2016 @ 14:56
    Yasir Butt
    0

    do you have skype id?

    can you share it?

  • Sharmarke Hujale 103 posts 346 karma points
    Dec 04, 2016 @ 15:11
    Sharmarke Hujale
    100

    Hi Yasir

    I made it work somehow - now it's showing what I want it show

    I changed this:

    var ydelser = Model.Content.Descendants("ydelser").FirstOrDefault();
    

    To this:

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

    Why do you think this can be the case?

  • Yasir Butt 161 posts 371 karma points
    Dec 04, 2016 @ 15:24
    Yasir Butt
    0

    Thats great!

    so its mean that direct descentdants was not working.

    So you may use like then you have strong type published model instead of dynamic object

    var ydelser = Model.Content.AncestorOrSelf(1).Descendants("ydelser").FirstOrDefault();
    
  • Sharmarke Hujale 103 posts 346 karma points
    Dec 04, 2016 @ 20:40
    Sharmarke Hujale
    0

    Yeah, it makes more since now!

    But thank you for helping me out, Yasir!

Please Sign in or register to post replies

Write your reply to:

Draft