Code Monkey home page Code Monkey logo

Comments (6)

sonicpunk avatar sonicpunk commented on June 9, 2024

In our config we are exposing twig for use in block rendering so:

// Exposing functions etc to twig can be done here: // @see https://github.com/amteich/kirby-twig/blob/master/doc/functions.md 'mgfagency.twig.env.functions' => [ '*renderBlock' => function (string $name, array $args = []) { // Render a block by twig template, if available if (file_exists(dirname(__DIR__) . '/templates/blocks/' . $name . '.twig')) { return twig('@templates/blocks/' . $name . '.twig', $args); } // otherwise fallback to standard snippet template (php) return snippet('blocks/' . $name, $args, true); }, ],

Is it possible to send $site in with $args to get access to it on the block level?

from kirby-twig.

seehat avatar seehat commented on June 9, 2024

I will look into it. In the meantime the site() function should work instead of $site.

from kirby-twig.

sonicpunk avatar sonicpunk commented on June 9, 2024

I am able to use a block php snippet for the output for the moment, but it would be nice to use one output language across the entire site.

from kirby-twig.

seehat avatar seehat commented on June 9, 2024

Yes you can send $site to it. I think this should work: (not tested)

<?php 
'mgfagency.twig.env.functions' => [ '*renderBlock' => function (string $name, array $args = []) { 
    // Render a block by twig template, if available 
    if (file_exists(dirname(__DIR__) . '/templates/blocks/' . $name . '.twig')) { 
        $args['site'] = site();
        return twig('@templates/blocks/' . $name . '.twig', $args); } // otherwise fallback to standard snippet template (php) 
        return snippet('blocks/' . $name, $args, true); 
    }, 
],

from kirby-twig.

seehat avatar seehat commented on June 9, 2024

@sonicpunk Did you have time to try the snippet?

from kirby-twig.

seehat avatar seehat commented on June 9, 2024

Closing this because of long time of inactivity.

from kirby-twig.

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.