Giter VIP home page Giter VIP logo

Comments (2)

NotJustPizza avatar NotJustPizza commented on June 1, 2024

I'm currently using own TwigBridge extension:

<?php

namespace App\Extensions\Twig;
use Stolz\Assets\Laravel\Facade as Assets;

class TwigAssets extends \Twig_Extension
{
    /**
     * {@inheritdoc}
     */
    public function getFunctions()
    {
        return array(
            new \Twig_SimpleFunction('assets_css', [$this, 'assets_css']),
            new \Twig_SimpleFunction('assets_js', [$this, 'assets_js']),
        );
    }

    public function assets_css()
    {
        return Assets::css();
    }

    public function assets_js()
    {
        return Assets::js();
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'Stolz/Assets Integration';
    }
}

from assets.

Stolz avatar Stolz commented on June 1, 2024

I'm not familiar with Twig so I can help you with that but what you could do is use a ViewComposer to automatically send the values of the Assets::css() and Assets::js() functions to your layout view:

<?php
namespace App\ViewComposers;
use Illuminate\Contracts\View\View;
class AssetsComposer
{
    public function compose(View $view)
    {
        $view->with([
            'js' => Assets::js(),
            'css' => Assets::css(),
        ]);
    }
}

To register your view composer use an existing Service provider or create your own:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class ViewComposerServiceProvider extends ServiceProvider
{
    public function boot()
    {
        view()->composers([
            'App\ViewComposers\AssetsComposer' => 'layouts.master',
        ]);
    }

    public function register()
    {
        //
    }
}

Then in your Twig layout just print the 'css' and 'js' variables.

from assets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.