用于管理布局的 Laravel 主题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16577158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:47:27  来源:igfitidea点击:

Laravel Theme for managing layouts

phplaravellaravel-4

提问by Miguel Borges

I'm starting to develop my master's thesis in laravel 4 and now needed a package for managing themes. The app would have, for example, 3 themes: admin, Theme1 and Theme2.

我开始在 laravel 4 中开发我的硕士论文,现在需要一个用于管理主题的包。例如,该应用程序将具有 3 个主题:admin、Theme1 和 Theme2。

Do you suggest any?

你有什么建议吗?

some features that would be interesting to have the package:

拥有该软件包的一些有趣功能:

  • management styles and scripts (add assets)
  • minification of assets
  • compilation lesscss (optional)
  • 管理风格和脚本(添加资产)
  • 资产缩减
  • 编译lesscss(可选)

回答by Jason Lewis

Sounds like you need to get your hands on the Cartalyst Themespackage. Ticks all your boxes as far as I can tell.

听起来您需要使用Cartalyst 主题包。据我所知,勾选你所有的方框。

If you're not keen on paying for a subscription then you might need to look at rolling your own. There's a number of asset management packages out there (Assetic, Basset, and Jeffrey Way's Laravel Guard) to help you get started on that front. As for the actual swapping out themes portion you'll need to implement something yourself there.

如果您不热衷于支付订阅费用,那么您可能需要考虑推出自己的订阅服务。有许多资产管理包(AsseticBassetJeffrey Way 的 Laravel Guard)可以帮助您开始这方面的工作。至于实际的换出主题部分,您需要在那里自己实现一些东西。

回答by Tee Plus

I wrote a package name "Theme".

我写了一个包名“主题”。

https://github.com/teepluss/laravel4-theme

https://github.com/teepluss/laravel4-theme

回答by windmaomao

This is my DIY way of managing themes in laravel and I have applied this to couple of my projects in the past, however this is not an automatic way that the other answers offers.

这是我在 laravel 中管理主题的 DIY 方式,我过去曾将其应用于我的几个项目,但这并不是其他答案提供的自动方式。

I found front-end person very creative, so I try to keep them as isolated as possible so that they don't have to know too much of the backend stuff before they can make contributions. Therefore, I created a folder called themesunder public.

我发现前端人员非常有创意,所以我尽量让他们保持孤立,这样他们就不必在做出贡献之前了解太多后端内容。因此,我创建了一个名为themesunder public的文件夹。

public
    themes
        default
            assets
            views
                layouts
                mockups
                pages
                partials

what's inside the default theme folder is really arbitrary, as long as you can keep your theme files manageable.

默认主题文件夹中的内容是任意的,只要您可以保持主题文件的可管理性。

Then I'll rely on the third party tool, ex. CodeKit etc. to do the css js compilation work. So this is not really Laravel specific topic any more.

然后我将依赖第三方工具,例如。CodeKit 等来做 css js 编译工作。所以这不再是 Laravel 特定的主题了。

To add another theme, just add another folder under themes folder. In order to get the above work, you still need to sort out the theme loader yourself, because we moved to a custom theme location. I'll put the following in the controller

要添加另一个主题,只需在主题文件夹下添加另一个文件夹。为了得到上面的工作,你仍然需要自己整理主题加载器,因为我们搬到了自定义主题位置。我会将以下内容放入控制器中

/**
 * Register a theme path relative to public
 *
 * @param string $name Theme name
 * @param string $path Theme path
 * @param string $asset_name Asset name of the theme, {$asset_name}_path will be registered at the template
 * @param string $asset_path Asset path of the theme, {$asset_name}_path will point to $asset_path
 */
protected function registerPublicPath($name, $path, $asset_name = '', $asset_path = '') {
    if (empty($asset_name)) {
        $asset_name = $name;
    }
    if (empty($asset_path)) {
        $asset_path = $path;
    }

    $path = public_path() . $path;
    View::addLocation($path);
    View::addNamespace($name, $path);
    View::share($asset_name . '_path', url('/') . $asset_path);
}

and call the default theme before use

并在使用前调用默认主题

    // Define a theme namespace folder under public
    $this->registerPublicPath(
        'default', '/themes/default/views',
        'asset', '/themes/default/assets'
    );

the way I did above is called "creating a theme engine" or "create a base theme" (ex. in Drupal).

我在上面所做的方式称为“创建主题引擎”或“创建基本主题”(例如在 Drupal 中)。

回答by igaster

If you have switched to Laravel 5 you can try my package with features like:

如果您已切换到 Laravel 5,您可以尝试我的软件包,其中包含以下功能:

  • Views & Asset seperation in theme folders
  • Theme inheritence: Extend any theme and create Theme hierarcies
  • 主题文件夹中的视图和资产分离
  • 主题继承:扩展任何主题并创建主题层次

Try it here: igaster/laravel-theme

在这里试试:igaster/laravel-theme