Copied to clipboard

Flag this post as spam?

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


  • Magnus Szatkowski 28 posts 149 karma points
    Aug 01, 2016 @ 09:10
    Magnus Szatkowski
    0

    How to use umbraco.field in href

    Hey Guys,

    This is probably a stupid question, but i cant seem to find an appropriate answer.

    What i need to do is use an Umbraco.Field in a href in a template, just like this piece of code:

            <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
            <a href="@Umbraco.Field("boks2Link")" target="_blank" class="hover-effect">
                <img class="img-responsive margin-top Info-Aside-Shadow" src="@Umbraco.Media(CurrentPage.gaaTilBoks2Billede).Url" alt="Se programmer">
                <div class="HeadLineTilbud">
                    <h2>@Umbraco.Field("gaaTilBoks2")</h2>
                </div>
            </a>
        </div>
    

    However, i can't use @Umbraco.Field("boks2Link") in href.

    What should i do to make this work?

    Thank you very much in advance!

    Kind regards, Magnus

  • David Peck 687 posts 1863 karma points c-trib
    Aug 01, 2016 @ 09:19
    David Peck
    100

    It depends what bok2Link is, but I'm going to use it is a content picker for this answer in which case this should work:

    @{
        var boks2LinkItem = Umbraco.TypedContent(Umbraco.Field("boks2Link"));
    }
    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
        <a href="@boks2LinkItem.Url" target="_blank" class="hover-effect">
            <img class="img-responsive margin-top Info-Aside-Shadow" src="@Umbraco.Media(CurrentPage.gaaTilBoks2Billede).Url" alt="Se programmer">
            <div class="HeadLineTilbud">
                <h2>@Umbraco.Field("gaaTilBoks2")</h2>
            </div>
        </a>
    </div>
    
  • Magnus Szatkowski 28 posts 149 karma points
    Aug 01, 2016 @ 09:31
    Magnus Szatkowski
    0

    Hey David,

    Thank you for your answer!

    Your solution doesn't seem to work as boks2Link is an external URL in a "Text Box" field. However i changed the code slightly which made it work.

    @{ var boks2LinkItem = Umbraco.Field("boks2Link"); }
        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
            <a href="@boks2LinkItem" target="_blank" class="hover-effect">
                <img class="img-responsive margin-top Info-Aside-Shadow" src="@Umbraco.Media(CurrentPage.gaaTilBoks2Billede).Url" alt="Se programmer">
                <div class="HeadLineTilbud">
                    <h2>@Umbraco.Field("gaaTilBoks2")</h2>
                </div>
            </a>
        </div>
    

    I thought i had tried this already, but now it works!

    Thanks a lot!

Please Sign in or register to post replies

Write your reply to:

Draft