teepluss / laravel-theme

Theme and asset managing for laravel
MIT License
546 stars 132 forks source link

Is there a theme helper? #132

Closed nasrulhazim closed 8 years ago

nasrulhazim commented 8 years ago

Hi there,

Is it possible to have a helper for the theme?

Usage will be something similar to response()->json(...), but for theme probably using response()->theme()->scope(...)

nasrulhazim commented 8 years ago

Propose theme helper syntax:

reponse()->theme('theme_name')->render('home.index', compact('users'));

OR

theme('theme_name')->render('home.index', compact('users'));

Set different layout during runtime is possible

theme('theme_name')->layout('mail')->render('home.index', compact('users'));
teepluss commented 8 years ago

Yes, there is a helper.

if ( ! function_exists('theme'))
{
    /**
     * Get the theme instance.
     *
     * @param  string  $themeName
     * @param  string  $layoutName
     * @return \Teepluss\Theme\Theme
     */
    function theme($themeName = null, $layoutName = null)
    {
        $theme = app('theme');

        if ($themeName)
        {
            $theme->theme($themeName);
        }

        if ($layoutName)
        {
            $theme->layout($layoutName);
        }

        return $theme;
    }
}