I would like to use getter instead general variable with dynamic snippets

7 years ago

Prado
Member | 21
+
0
-

required has triggered error: “Undefined property: Article::$getId”

{snippet article-$article->getId()}
...
{/snippet}

workaround:

{var $articleId=$article->getId()}
{snippet article-$articleId}
...
{/snippet}

(I'm not using Nette/Object as parent class of Article and I don't want to be.)

7 years ago

Majkl578
Moderator | 1379
+
0
-

That wouldn't work even in PHP itself:

class Foo {
    public function getBar() { return "hello"; }
}

$foo = new Foo();

echo "$foo->getBar()"; // Notice: Undefined property: Foo::$getBar

You might try something like this:

{snippet "article-{$article->getId()}"}

Not sure if that would work though.