Question

It seems F3 framework doesn't handle php function calls within a page? I have a php navigation bar, which is uniform site-wide. I call up my layout page in my controller class thus: Template::serve('layout.php'). In the layout page, I include the navigation bar thus: <F3:include href="navbar.php" />. Within the navbar (navigation) file, I call a utility function siteUrl which gets the absolute url to a resource e.g. css or .js file. This function is defined in an include file which I include as follows: require_once "lib/globals.php. Within the navbar.php, I use the siteUrl as follows for example:

<img id="logo" alt="logo" src="<?php echo siteUrl('small-logo.png') ?>" /> 

This doesn't seem to work. When I view the generated source of the page, the src section of the img tag is an empty string: "". However, when I call the navigation bar from other pages that are not using the F3 framework (i.e. pages that are not being routed by F3::route. Not all pages of the website are routed using F3), it works fine.

What could be the problem? How could I call a php function from within a php page that is being rendered using Template::serve? It seems the entire content between the <?php ?> tag is not being executed when the page is being served by F3. Echo statements are not being displayed. Thanks for responses.

Was it helpful?

Solution

Template::serve() does not allow PHP. It is a templating engine. There are things you can do. You can define a function using F3::set('sum',function($a,$b){return 1+2;}); and then reference that function in the template with {{@sum(1,2)}}. I would re-read the templating documentation on the fatfree site: http://bcosca.github.com/fatfree/#views-templates

Again, the reason PHP is not working is because you are using Template::serve() and are therefore using the templating features of Fatfree. If you want to use PHP, I believe you can use F3::render() instead and it will render the page, allowing PHP, but you will lose all the templating functionality.

OTHER TIPS

you can use raw php within the template tokens wrapped by curly brakets like this:

<img id="logo" alt="logo" src="{{ siteUrl('small-logo.png') }}" />

it will echo it automatically.

but using F3::set('image.smallLogo',siteUrl('small-logo.png')) to define the image paths and grap them with a simple {{@image.smallLogo}} feels much better.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top