f3-factory / fatfree-core

Fat-Free Framework core library
GNU General Public License v3.0
206 stars 89 forks source link

Template alias filter not replacing wildcard token #348

Closed paclucio closed 2 years ago

paclucio commented 2 years ago

Hi all,

As the title says, alias filter does not replace wildcard, only the named token as per docs

F3: 3.7.3 and 3.8.0 Route: GET @product: /produto/@pid/* = \Controllers\Viewport->product HTML: <a href="{{ 'product', 'pid='. @product.productid .',2='. \Web::instance()->slug( @product.title ) | alias }}" title="{{ @product.title }}">

It renders http://domain.stg/produto/meP9UCfv/*

Thank you.

xfra35 commented 2 years ago

Hi @paclucio It appears that the docs are obsolete. The alias and build functions have been refactored a long time ago.

Here's how they work:

echo $f3->build('/produto/@pid', ['pid'=>'foo']); // /produto/foo
echo $f3->build('/produto/@pid/*', ['pid'=>'foo','*'=>'bar']); // /produto/foo/bar
echo $f3->build('/produto/*/@pid/*', ['pid'=>'foo','*'=>['bar','baz']]); // /produto/bar/foo/baz

In other words, you should pass an argument named * with:

So in your example, you should rewrite your code like this:

<a href="{{ 'product', 'pid='. @product.productid .',*='. \Web::instance()->slug( @product.title ) | alias }}">

or

<a href="{{ 'product', [ 'pid' => @product.productid, '*' => \Web::instance()->slug( @product.title ) ] | alias }}">
paclucio commented 2 years ago

Thank you very much @xfra35

Used your second more elegant solution.

Good luck!