OctoberCMS Get Theme Settings data in Api/Web service

- 1 answer

Ad

I have created an OctoberCMS theme which works very well. And i have my current and activated theme.yaml like this.

theme.yaml

name: 5P Group
description: '5P Group OctoberCMS theme. A client website that contains preconfigured pages for static pages, a blog and client area..'
author: Technobrave
homepage: 'http://technobrave.com/'
code: ''
form:
    fields:
        site_logo:
            label: Site Logo
            comment: The website logo as it should appear on the front-end
            type: fileupload
            mode: image
            imageHeight: 32
            imageWidth: 443

As you can see i have added a Site Logo label through which admin can upload a logo and i will show it up front, which is working fine as i am able to show logo at front area like this.

menu.htm

{% if this.theme.site_logo  %}
<img src="{{ this.theme.site_logo.path }}" width="100%" height="auto"/>
{% else %}
<img src="{{ 'assets/images/logo.png'|theme }}" width="100%" height="auto"/>
{% endif %}

But the thing is i am also creating an api and i want to do the same thing in that api. This is what i am trying.

routes.php

    use System\Classes\SettingsManager;

    /* API to get Website Logo Dynamically Starts */

    Route::post('/getWebsiteLogo', function () 
    {
        $settings = Settings::instance();

        print_r($settings);



    });
    /* API to get Website Logo Dynamically Ends */

But i am having an error saying

Class 'Settings' not found

Can someone guide me or suggest me how can i accomplish the same thing, or say how to get the dynamic website logo in one of my apis ?

Thanks

Ad

Answer

Ad

Ok guys, thanks for your support .. eventually i have worked around like this.

routes.php

<?php 
use Cms\Classes\ComponentBase;
use RainLab\Pages\Classes\Router;
use Cms\Classes\Theme;

/* API to get Website Logo Dynamically Starts */
Route::post('/getWebsiteLogo', function () 
{
    $theme = Theme::getActiveTheme();
    $logo_url = '';
    if($theme->site_logo['attributes']['disk_name'])
    {
        echo $theme->site_logo->path; 
    }
}
?>

Thanks for help and support. Highly appreciated.

Ad
source: stackoverflow.com
Ad