Copied to clipboard

Flag this post as spam?

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


  • Jhon 87 posts 162 karma points
    Apr 19, 2018 @ 10:49
    Jhon
    0

    Content picker links

    Hi,

    I have written this code, now i am getting error. If i remove @ , it works , but the title link is displaying wrong like : http://localhost:61946/1296

    i need to display like :http://localhost:61946/debatmoeder/links-mappe/demo/

    link data type content picker see my code:

    enter image description here

    Output:

    enter image description here

    The same code one of my friend has written in umbraco 4. i have written umbraco 7. enter image description here

  • Kevin Jump 2310 posts 14695 karma points MVP 7x c-trib
    Apr 19, 2018 @ 11:08
    Kevin Jump
    0

    Hi

    replacing @banner.GetPropertyValue("link") with @banner.Url should work.

    There are some bigger changes going on between your umbraco 7 code and what the Umbraco 4 way of doing it was.

    but in principle now you are working with TypedContent items (IPublishedContent) items. and these have some basic core properties like

    .Name
    .Url
    .CreatedDate 
    

    but for custom properties you do

    .GetPropertyValue("property").
    

    the older code is using Dynamic objects (so banner.property) this is being phased out of umbraco, so its better to stick to the top one.

    itsa a bit old, but the Umbraco Stronly Typed Cheetsheet (https://our.umbraco.org/FileDownload?id=8864) might give you a good overview of the properties you can call.

  • Jhon 87 posts 162 karma points
    Apr 19, 2018 @ 11:18
    Jhon
    0

    No, i dont want @banner.Url. I want @banner.link .url

  • Kevin Jump 2310 posts 14695 karma points MVP 7x c-trib
    Apr 19, 2018 @ 11:22
    Kevin Jump
    0

    Hi

    if "link" is a Content Picker (so the editor picks a single page)

    var link = banner.GetPropertyValue<IPublishedContent>("link");
    if (link != null) 
    {
       <a href="@link.Url">link text</a>
    }
    

    K

  • Jhon 87 posts 162 karma points
    Apr 19, 2018 @ 12:35
    Jhon
    0

    Hi,

    The code is working.

    Just i am playing with code(foreach).

    i have written foreach two different places. If i write on the top , the code is displying error. See my code .

    what is the difference.Caan you please share.

    enter image description here

    See output: enter image description here

    Here i have written foreach see this code. it works fine. enter image description here

  • Jhon 87 posts 162 karma points
    Apr 19, 2018 @ 18:50
    Jhon
    0

    Can you please help me

  • Kevin Jump 2310 posts 14695 karma points MVP 7x c-trib
    Apr 19, 2018 @ 18:56
    Kevin Jump
    0

    Hi

    Sorry I missed the notification for that earlier one.

    For the top If statement you need to wrap the code as below:

       @{
           var link....
           If () {
    
          }
        }
    

    This helps .net identify the code from the html.

  • Jhon 87 posts 162 karma points
    Apr 20, 2018 @ 07:18
    Jhon
    0

    ok , I have written like that. Can you Please see my code.

    enter image description here

    Output:

    enter image description here

  • Kevin Jump 2310 posts 14695 karma points MVP 7x c-trib
    Apr 20, 2018 @ 08:18
    Kevin Jump
    0

    Hi sorry, probibly partly my fault for answering on a mobile .

    you need to wrap the code that is inside the DIV elements in @{ }

    e.g.

    <div id="textBlock">
    @{
         var link = banner.GetPropertyValue<>....
    
     // if code here
    }
    </div>
    
  • Jhon 87 posts 162 karma points
    Apr 20, 2018 @ 08:38
    Jhon
    0

    Hi,

    Yes , it works . I have a little doubt . Why we use like that.

  • Jhon 87 posts 162 karma points
    Apr 20, 2018 @ 09:07
    Jhon
    0

    I can understand. I have written this code , it works fine. I used many places

    @{ }

    like that . Is it correct way?

    enter image description here

  • Kevin Jump 2310 posts 14695 karma points MVP 7x c-trib
    Apr 20, 2018 @ 09:51
    Kevin Jump
    0

    yeah it looks right.

    If your code is within a html tag (so in a

    . ..
    or similar) the Razor parser can't tell what is code and what is html so you have to give it a hint - the @{ } is defining the boundry between code and html

  • Jhon 87 posts 162 karma points
    Apr 23, 2018 @ 06:47
    Jhon
    0

    I can understand , Thank you so much.

Please Sign in or register to post replies

Write your reply to:

Draft