Twig on F3 v3

619 views
Skip to first unread message

Sergio Guamán

unread,
Dec 24, 2012, 10:57:52 AM12/24/12
to f3-fra...@googlegroups.com
Hi,

Has Someone built Twig templates on F3 v3?

thank's in advance

Sergio Guamán
La Serena
Chile

Sergio Guamán

unread,
Dec 27, 2012, 9:21:58 PM12/27/12
to f3-fra...@googlegroups.com
I implemented it...thank's anyway...

Juan José Prieto

unread,
Jan 25, 2013, 11:31:24 PM1/25/13
to f3-fra...@googlegroups.com
oye como implementaste el twig, estoy tatando de usar el sistema de plantillas pero me aparece en blanco conla funcion template::serve(),

gracias.

Sergio Guamán

unread,
Jan 28, 2013, 8:45:58 AM1/28/13
to f3-fra...@googlegroups.com
Que versión de F3 estas usando?

What version of F3?

phpbutcher

unread,
Feb 26, 2014, 3:17:59 PM2/26/14
to f3-fra...@googlegroups.com
Sergio,

Any chance you could tell the basics of how you did it? I'm pretty sure I'm not the only one that would like to know.

Thanks!

bcosca

unread,
Feb 26, 2014, 3:39:11 PM2/26/14
to f3-fra...@googlegroups.com
This is for an old version of F3, but the principles are pretty much the same.

phpbutcher

unread,
Feb 26, 2014, 6:21:03 PM2/26/14
to f3-fra...@googlegroups.com
Thanks for the link!


On Monday, December 24, 2012 10:57:52 AM UTC-5, Sergio Guamán wrote:

phpbutcher

unread,
Feb 27, 2014, 8:12:23 AM2/27/14
to f3-fra...@googlegroups.com
Okay so I looked through that tutorial and I was able to hook in Twig easily enough, but I'd like to tie it into the framework a little more. At least enough so that I don't have to do "global $twig" where ever I need to use it. I tried doing something like $f3->set('twig', $twig); so I could use $this->f3->get('twig)->render() but it didn't seem to like that.

Does anybody have any suggestions for doing something like this?


On Monday, December 24, 2012 10:57:52 AM UTC-5, Sergio Guamán wrote:

matt smith

unread,
Feb 28, 2014, 8:19:54 AM2/28/14
to f3-fra...@googlegroups.com
I played around with twig before deciding to stick with the f3 templating. I know this worked in my testing, don't know if it's optimal or such, but I had this in my index.php...

//Twig
require_once 'lib/Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('ui');
$twig = new Twig_Environment($loader, array(
    'cache' => $f3->get('TEMP'),
'debug' => true,
));
$f3->set('twig',$twig);

...Then you can call twig with $f3->get('twig')->twigfunction.

phpbutcher

unread,
Feb 28, 2014, 9:23:31 AM2/28/14
to f3-fra...@googlegroups.com
Thanks for that Matt. That's at least what I *thought* I did but I'll try it again. 

The other thing I was wondering is if there's an OO way of getting the hotspots that are automatic to F3 like @BASE and @site available to Twig in the same manner. It's not a big deal but would be nice to have.


On Monday, December 24, 2012 10:57:52 AM UTC-5, Sergio Guamán wrote:

Bond

unread,
Mar 1, 2014, 2:12:52 AM3/1/14
to f3-fra...@googlegroups.com
According to the tutorial, you should do

{{ 'BASE'|f3 }}

You can get all variables set using f3->set() the same way.

Or you can do

$twig->addGlobal( 'BASE', $f3->get( 'BASE' ) );

So, you can get it in your templates like {{ BASE }}

Bond

unread,
Mar 1, 2014, 4:44:05 AM3/1/14
to f3-fra...@googlegroups.com
I agree. F3 templating engine allows you run PHP code in the template, I've not been able to do the same with twig without writing my own filters or tags.

Is there a way to write filters in F3?

ikkez

unread,
Mar 1, 2014, 8:58:43 AM3/1/14
to f3-fra...@googlegroups.com
What do you mean with own filters?

Bond

unread,
Mar 1, 2014, 11:25:48 AM3/1/14
to f3-fra...@googlegroups.com
I meant with F3 you could just write {{ json_decode( @var ) }} with Twig you have to do {{ var | json_decode }} after writing a filter function.

I was asking if there was a way to write custom filters in F3, something like

{{ var | custom_filter }}

Not that I need it anyway, just asking.

ikkez

unread,
Mar 1, 2014, 1:16:50 PM3/1/14
to f3-fra...@googlegroups.com
ah yeah, understand.
yes this is already there, but a still pending enhancement, see: https://github.com/bcosca/fatfree/pull/550
Reply all
Reply to author
Forward
0 new messages