Developer forum

Forum » CMS - Standard features » Global:Extranet [CustomUserField]

Global:Extranet [CustomUserField]

Thomas Jensen
Reply

HI

In template (like productlist), is there a way to get data from a custom user fields
like @GetGlobalValue("Global:Extranet.Name"), but with a custom field

an option but not a solution, is to use Extranet module and move it over with snippets
The snippet get pased in last so you can not do things like the following on it
if(myUserCustomField == "blue"){ <p>show some content form this module (not the Extranet module) here<p>}


Regards Thomas


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Thomas,

Here is a sample template which renders all custom fields and values for the current user...

@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
<div>
    <h1>User - Custom fields</h1>
    <table>
        @{
            var user = Pageview.User;
 
            if (user != null)
            {
                foreach (var customFieldValue in user.CustomFieldValues)
                {
                    var field = customFieldValue.CustomField;
                    var value = customFieldValue.Value;
 
                    <tr>
                        <th>@field.Name</th>
                        <td>@value</td>
                    </tr>
                }
            }
        }
    </table>
</div>

Best regards,
Morten

 
Thomas Jensen
Reply

Hi Morten

Thanks
That was what i was looking for

Now what i did:
@functions {
    bool MyCustomCheckbox = false;
}
@{
    var user=Pageview.User;
    if(user != null){foreach (var customFieldValue in user.CustomFieldValues){
        if(customFieldValue.CustomField.SystemName == "TheSystemNameForMyCustomCheckbox"){MyCustomCheckbox = Convert.ToBoolean(customFieldValue.Value.ToString());}
    }}
}


And then i can use it in the helper functions
<p>@MyCustomCheckbox</p>
@if(MyCustomCheckbox){
<p>Some content if true</p>
}

 

Regards Thomas

 

You must be logged in to post in the forum