0

I have a custom member field that can have a value of "1", "2" or "3"

In channel entries I need to output the value of one of three custom fields, depending the member field value.

ie : {field_{member_field}}

I've tried to put together a plugin but I'm a bit stuck in parsing order issues.

Any ideas ?

  • Could you be a little more clear on what you've tried? My first thought is to use a mapping array in the plugin (map 1 to field_id_48, map 2 to field_id_whatever, etc...) – jrothafer Aug 18 '15 at 13:51
  • The plugin just checks the value of the logged in member's custom field and outputs it to the template. Then in the template I've tried {field_{exp:my_plugin}} but the template outputs {field_1} which would be correcte if only it was parsed by the template engine ! – laurent Aug 18 '15 at 16:13
0

If it can help anyone, here is how I solved it:

1 - Forget the plugin idea

2 - Allow PHP on input in the template

3 - Query the database to get the custom member profile field value

    $member_id = ee()->session->userdata('member_id');

    if ( $member_id ) {

        $results = ee()->db->select('m_field_id')
            ->from('exp_member_data')
            ->where(array(
                'member_id' => $member_id
            ))
            ->get();

        $value = $results->row('m_field_id');

    }

4 - echo the php value in the template tag

{field_<?=$value?>}
| improve this answer | |
  • That would do it. of if you wanted a PHP-less solution you could use an embed to defeat parse order (embed variables are parsed before module tags so pass the {member_field} as a parameter to the embed, and in the embed do {field_{embed:var}}. Might work, might not. Don't forget to come back and tick your answer as _the_answer in 2 days!! – Blatant Aug 19 '15 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.