News:

Wondering if this will always be free?  See why free is better.

Main Menu

Custom Profile Fields

Started by Chen Zhen, August 01, 2022, 10:40:24 PM

Previous topic - Next topic

Chen Zhen


I'm not sure if it's just something I'm not seeing in the code, something that was missed for the devs or more than likely I've gone about something in a different way which is why I'm not seeing the expected behavior.

I've been adding to the profile summary for a few mods using the integrate_load_custom_profile_fields hook.
Within my hook functions I've been adding to the $context['custom_fields'] global which is working just fine.
However there seems to be no way of properly inserting a horizontal rule between additional key entries.
I've come up with a way of doing it for my own mods but if another mod adds to the array they run into the possibility of having no HR or a double HR between key entries.

The loop: ../Themes/default/Profile.template.php
foreach ($context['custom_fields'] as $field)
echo '
<dt>
<strong>', $field['name'], '</strong><br>
<span class="smalltext">', $field['desc'], '</span>
</dt>
<dd>
', $field['input_html'], '
</dd>';

.. for anyone adding to that array via the hook call, it does not place a horizontal rule between each key.
Unless I'm going about adding to that template in the wrong way?!

My SMF Mods & Plug-Ins

WebDev


"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Chen Zhen

Actually, I was looking at the wrong part of the template yet my findings are the same.
This is concerning the profile summary so the code that uses the global array shown below..

I used 0 as the standard placement & output_html for what is being displayed.

The Source file loop: ../Sources/Profile-View.php
    $context['print_custom_fields'] = array();
    // Any custom profile fields?
    if (!empty($context['custom_fields']))
        foreach ($context['custom_fields'] as $custom)
            $context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;

The template loop: ../Themes/default/Profile.template.php
    // Any custom fields for standard placement?
    if (!empty($context['print_custom_fields']['standard']))
    {
        $fields = array();

        foreach ($context['print_custom_fields']['standard'] as $field)
            if (!empty($field['output_html']))
                $fields[] = $field;

        if (count($fields) > 0)
        {
            echo '
            <dl class="settings">';

            foreach ($fields as $field)
                echo '
                <dt>', $field['name'], ':</dt>
                <dd>', $field['output_html'], '</dd>';

            echo '
            </dl>';
        }
    }

My SMF Mods & Plug-Ins

WebDev


"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Arantor

It was never meant to add an HR between keys. It was always intended that the list of fields with the same display settings would display as a group of items and not individual items with separators.

I appreciate this isn't what you want, but this is working as intended by its creator.

Chen Zhen


Alright thanks for the response.

Imo it would look better if various mods adding to that array could partition their display.
Ie. letting the mod author add a named key of "last_item" equal to "hr" so it adds a horizontal rule after the html output.
Where if it's void of the named key of last_item or it's empty then it doesn't add one.
I suppose I can put this in a feature request.

My SMF Mods & Plug-Ins

WebDev


"Either you repeat the same conventional doctrines everybody is saying, or else you say something true, and it will sound like it's from Neptune." - Noam Chomsky

Advertisement: