Giter Club home page Giter Club logo

Comments (3)

StrangerPings avatar StrangerPings commented on September 9, 2024

@HugoWijdeveld I am also getting the same error, did you manage to find a solution?

from dynamicpdf-plugin.

HugoWijdeveld avatar HugoWijdeveld commented on September 9, 2024

@StrangerPings I found a workaround by replacing the partial with a function.
Register a markup tag in the Plugin.php:

use Twig;

public function registerMarkupTags() {
return [
    'reportField' => function($args = [ ]) {
        foreach( $args as $key => $arg ) {
            $vars[$key] = $arg;
        }
        $file = $vars['file'];
        $partal = 'path/to/standard/partials/folder/' .  $file . '.htm';
        return Twig::parse($partial, $vars);
    },
];

Now pass variables to the partial. Instead of using {% partial %}, in the view file use

{{ reportField({
    file: 'my_file_name',
    var1: 'variable1 value',
    var2: variable.from.component
}) }}

In this example you would have a partial called 'my_file_name.htm' in the folder 'path/to/standard/partials/folder/'. This could look something like:

<div>
    <p>{{ var1 }}</p>
    <p>{{ var2 }}</p>
</div>

Good luck!

from dynamicpdf-plugin.

AllARTSoftworks avatar AllARTSoftworks commented on September 9, 2024

@HugoWijdeveld your post was really inspiring.

I changed it a bit, tested and working on WinterCMS.

In Plugin.php:


use \Winter\Storm\Support\Facades\Twig;
use \Illuminate\Support\Facades\File;

public function registerMarkupTags()
    {
        return [
            'functions' => [
                'partial' => function ($args = []) {
                    foreach ($args as $key => $arg) {
                        $vars[$key] = $arg;
                    }
                    $file = $vars['file'];
                    $partial = File::get(plugins_path() . '/me/myplugin/views/pdf/partials/' . $file . '.htm');
                    return Twig::parse($partial, $vars); // using Winter
                },
            ]
        ];
    }

then in my view, as per your reply:

    {{ partial({
        file: 'my_partial_filename',
        title: 'My Title',
    }) }}

and in my partial, in /me/myplugin/views/pdf/partials/my_partial_filename.htm:

<table class="my-class">
    <tr>
        <td>
            {{ title }}
        </td>
    </tr>
</table>

Hope it helps.

from dynamicpdf-plugin.

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.