Roots Discourse

Shortcodes and how to display each part of the array

I am working with Sage 9. In my controller, I have the following function which returns data from the API:

    public static function get_compare_providers() {
    global $bbn_api;
    $selectedProviders = get_field('compare_providers');

    $provider1 = $selectedProviders['compare_providers']['provider1_provider']['value'];
    $provider2 = $selectedProviders['compare_providers']['provider2_provider']['value'];

    $api_url = App::getAPIBaseURL() . '/Providers/compare?leftProviderID=' . $provider1 . '&rightProviderID=' . $provider2;
    // var_dump($api_url);die();
    $data = $bbn_api->generate_get($api_url);
     var_dump($data);die();

    return json_decode(json_encode($data), true);
}

When I do a var_dump, I see the entire dataset returned.

object(stdClass)[1892]
public 'LeftProviderName' => string 'someprovidername'...

I also have a blade that calls this function and it has the data as well.

I then map an array of shortcodes in my app\shortcodes.php file, which all other shortcodes work in this array.

However, the latest addition is returning Array -
‘GetCompareProviders’ => ‘partials/compare-v2/shortcodes/get-compare-providers’

Within the aforementioned file, is a simple call to the function within the controller:
{!! TemplateCompareV2::get_compare_providers() !!}

Within the wysiwyg, I use the following shortcode - [GetCompareProviders field=‘LeftProviderName’] - which returns ‘Array’

How do I just return the left provider name, which is the first element of the array that is returned by the shortcodes?

image

This topic was automatically closed after 42 days. New replies are no longer allowed.