Copied to clipboard

Flag this post as spam?

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


  • ismini 14 posts 135 karma points
    Feb 21, 2020 @ 14:18
    ismini
    0

    template weird behaviour

    Hi guys,

    I want your help because I'm going crazy...

    I have the following block code in my template:

    if(@CurrentPage.HasValue("secondaryOfferImage")){
        secondaryOffer.ActionButtons = new ActionButtons() {
            Desktop = new ButtonItem() {
                Caption = @CurrentPage.secondaryActionButtons.ActionButtonDesktop[0].caption,
                Link = @CurrentPage.secondaryActionButtons.ActionButtonDesktop[0].link,
                OpenNewWindow = @CurrentPage.secondaryActionButtons.ActionButtonDesktop[0].newWindow
            },
            Mobile= new ButtonItem() {
                Caption = @CurrentPage.secondaryActionButtons.ActionButtonMobile[0].caption,
                Link = @CurrentPage.secondaryActionButtons.ActionButtonMobile[0].link,
                OpenNewWindow = @CurrentPage.secondaryActionButtons.ActionButtonMobile[0].newWindow
            },
            ActionName = @CurrentPage.secondaryActionButtons.ActionButtonNameNativeApps,
            ActionLink = @CurrentPage.secondaryActionButtons.ActionButtonLinkNativeApps
        };
    
        secondaryOffer.Title = @CurrentPage.secondaryTitle;
        secondaryOffer.Description = @CurrentPage.secondaryDescription.ToString();
        secondaryOffer.OfferImage = @Umbraco.Media(Convert.ToString(CurrentPage.secondaryOfferImage)).Url;
    }
    

    Everything worked perfectly until I decided to move the last three lines over the secondaryOffer.ActionButtons, that is, the code was as follows:

    if(@CurrentPage.HasValue("secondaryOfferImage")){
        secondaryOffer.Title = @CurrentPage.secondaryTitle;
        secondaryOffer.Description = @CurrentPage.secondaryDescription.ToString();
        secondaryOffer.OfferImage = @Umbraco.Media(Convert.ToString(CurrentPage.secondaryOfferImage)).Url;
        secondaryOffer.ActionButtons = new ActionButtons() {
            Desktop = new ButtonItem() {
                Caption = @CurrentPage.secondaryActionButtons.ActionButtonDesktop[0].caption,
                Link = @CurrentPage.secondaryActionButtons.ActionButtonDesktop[0].link,
                OpenNewWindow = @CurrentPage.secondaryActionButtons.ActionButtonDesktop[0].newWindow
            },
            Mobile= new ButtonItem() {
                Caption = @CurrentPage.secondaryActionButtons.ActionButtonMobile[0].caption,
                Link = @CurrentPage.secondaryActionButtons.ActionButtonMobile[0].link,
                OpenNewWindow = @CurrentPage.secondaryActionButtons.ActionButtonMobile[0].newWindow
            },
            ActionName = @CurrentPage.secondaryActionButtons.ActionButtonNameNativeApps,
            ActionLink = @CurrentPage.secondaryActionButtons.ActionButtonLinkNativeApps
        };
    }
    

    What the hell ?! :|

  • Kevin Jump 2341 posts 14868 karma points MVP 8x c-trib
    Feb 21, 2020 @ 16:10
    Kevin Jump
    0

    Hi,

    I think its the '@' symbols.

    you don't need them when you are assigning values - the '@' is short hand razor is using to write out to the page, as you are assigning things you can/should remove it.

Please Sign in or register to post replies

Write your reply to:

Draft