Copied to clipboard

Flag this post as spam?

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


  • MuirisOG 382 posts 1284 karma points
    May 27, 2016 @ 13:03
    MuirisOG
    0

    changing the field property for the umbraco:Item control

    Hi there Is there any way to alter the value of the field attribute in the umbraco:Item element in the master template, depending on the value held in a session variable?

    I would like to use it when the user swaps language (stored in a Session variable).

    <umbraco:Item field="en_gb_content" runat="server" />
    

    would become

    <umbraco:Item field="cy_gb_content" runat="server" />
    

    through something like this:

    <umbraco:Item field="(@Session("lang"))_content" runat="server" />
    

    I've come across some really useful solutions using macros, and I've got a quick and dirty solution using a ContentPlaceHolder.

    Thanks in advance, Muiris

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Oct 11, 2016 @ 16:53
    Alex Skrypnyk
    0

    Hi Muiris,

    Are you using masterpages with Umbraco 7?

    /Alex

  • MuirisOG 382 posts 1284 karma points
    Oct 11, 2016 @ 17:05
    MuirisOG
    101

    Hi Alex,

    yes, I am using masterpages.

    I've solved my problem using a usercontrol in my templates, which looks something like this:

    <nns:nnsUmbracoField umbracoFieldName="short_title" Language="" runat="server" />
    

    The language is set / checked in every template, and depending on the value, it prefixes my fieldname and the usercontrol outputs the value accordingly.

    The Language parameter defaults to the current language or English if it is not set.

    Perhaps not the most elegant solution, but it solves the problem I faced of using one template for two languages.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Oct 11, 2016 @ 17:11
    Alex Skrypnyk
    0

    Thanks for sharing,

    For WebForms it's great solution!!!

    Topic is solved.

    /Alex

  • MuirisOG 382 posts 1284 karma points
    Jul 10, 2017 @ 15:23
    MuirisOG
    0

    Hi Alex

    I've had to rewrite my solution for RTE properties of doctypes, if they contain a usercontrol, and thought it might be relevant to this discussion.

    Here's the link:

    https://our.umbraco.org/forum/templates-partial-views-and-macros/86736-page-events-eg-page_load-are-being-fired-twice

Please Sign in or register to post replies

Write your reply to:

Draft