L
L
lllyx2019-09-19 21:55:56
MODX
lllyx, 2019-09-19 21:55:56

How to display an instance of a class in a ModX view?

Wrote a snippet

<?php
class txaTagApp
{
    public function getCss()
    {
        echo '/assets/bricks/css';
    }
}

how to withdraw?
$class->getCss();
Worth xPDO
MODX Revolution 2.7.1-pl

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-09-24
@lllyx

The snippet itself is not interactive, it is executed as a piece of raw PHP code. So the simplest implementation would be something like this:

switch ($action) {
    case 'firstAction' :
        $class->firstMethod();
        break;
    case 'secondAction' :
        $class->secondMethod();
        break;
}

And then, at the right place in the template, the snippet with the passed parameter is called: Or Fenom:
{'!yourSnippet' | snippet : ['action' => 'firstAction']}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question