Code Monkey home page Code Monkey logo

foil's Introduction

FOIL

PHP template engine, for PHP templates.


travis-ci status codecov.io license release


Foil brings all the flexibility and power of modern template engines to native PHP templates. Write simple, clean and concise templates with nothing more than PHP.

Key Features

  • Templates inheritance (you'll never miss Twig or Blade)
  • Clean, concise and DRY templates
  • Dozen of ready-made helper functions and filters
  • Easily extensible and customizable
  • Multiple template folders with file auto-discover or custom picking
  • Auto or manual data escape
  • Powerful context API (preassign data to templates using conditions)
  • Framework agnostic, centralized API for very easy integration
  • Composer ready, fully unit and functional tested, PSR-1/2/4 compliant

...and many more

Why?

Templates engines like Twig, or Blade are a great thing, really.

However, to use them one needs to learn another language with its own syntax and rules.

Moreover, using compiled engines to use even a simple PHP function one needs to write engine extension.

On its side, PHP is already a templating language, but honestly it's not a good one, because it's missing pivotal features of modern template engines, like template inheritance.


Requirements

Foil is framework agnostic, only thing needed is PHP 5.4+ and Composer to add Foil to you PHP project.


License

Foil is open source and released under MIT license. See LICENSE file for more info.

Question? Issues?

Foil is hosted on GitHub. Feel free to open issues there for suggestions, questions and real issues.

Who's Behind Foil

I'm Giuseppe, I deal with PHP since 2005. For questions, rants or chat ping me on Twitter (@gmazzap) or on "The Loop" (Stack Exchange) chat. Well, it's possible I'll ignore rants.

foil's People

Contributors

avant1 avatar barryo avatar brad-jones avatar fbraem avatar gmazzap avatar kraftner avatar thevikas avatar vinkla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

foil's Issues

Autoload path - possible issue?

Hi Giuseppe,

In documentation autoload path is:

require 'vendor/autoload.php';

However normally as the vendor folder is located above the public folder it should be :

require '../vendor/autoload.php';

or better

require_once DIR.'/../vendor/autoload.php';

Ionut

'Template folders must be readable paths' exception

Hi Giussepe,

Another Plates refugee here. Thank you for this package. I am having trouble with what is probably the most elementary thing: the templates path.

What am I doing wrong?

The template path I want to use is directory_root/public/templates

The directory exists

If I am enter the following in a file inside public:

$foil = Foil\Foil::boot([
'folders' => ['/public/templates']
]);

I receive this: "Uncaught exception 'InvalidArgumentException' with message 'Template folders must be readable paths.'"

If I enter:

$foil = Foil\Foil::boot([
'folders' => ['templates']
]);

Then I get this error: Uncaught exception 'LogicException' with message '"start" is not a registered Foil callback.

Would you please provide just a little guidance regarding what Foil is looking for in terms of a template path?

Can't render double extension templates without postfix

        $engine = Foil\engine([
            'ext'     => ['tpl.php'],
            'folders' => ['path/to/templates']
        ]);
        // trying to render path/to/templates/home.tpl.php
        $engine->render('home'); 

this produces

Uncaught exception 'RuntimeException': home is not a valid template name

Do I miss something or this is currently not possible with Foil ?

Arraization(?) is turning my Eloquent collections into strings (not arrays)

I'm passing in Eloquent Collections like so:

$engine->render('index/index', [
    'questions' => $questions,
);

If I var_export in the my controller class, the variable is set as an instance of Collection, but if I var_export within the template it's not an object, it's not an array even, but is a json_encoded string! I guess I could json_decode but is this the desired behaviour?

Also, how do I turn off Arraization for all templates? I might not wish to have this feature for now. Thanks

Add a shortcut / alias variable

At the moment inside templates pretty everything is done via $this variable.

I think would be nice to have a short-named (probably one letter) variable that allow to access all features with less typing.

that would be as easy as to add $T = $this; before requiring template files.

After that inside templates, will be possible

$T->section('foo');

instead of

$this->section('foo');

Moreover, syntax to access variables:

$T->varname

is not very much longer than

$varname

Considering Foil has no global variables in templates that should not cause any name conflict and, since $this is still available, that will not cause any backward compatiblity break.

New line in doRender of Engine class

Hello Giuseppe, I'm making a wordpress theme that uses Foil, I see a difference on the output when using the get_template_part() and $this->insert() or $this->section() or similar; it's like if the new lines at the end of each section/part gets deleted:

For example, this:

<html <?php language_attributes() ?>>
<?php #get_template_part('templates/head'); ?>
<?= $T->insert('head') ?>

<body <?php body_class() ?>>

Outputs:

<html lang="es-MX">
<head>
...
</head>
<body class="home blog">

The space (or newline) between closing head and body is deleted or if is a closing tag โ€“which I like to have on its own lineโ€“ merges with the preceding line, so it changes a little bit the expected result. I know is not a critical thing but I'd like to have the same behavior than the wordpress function.

Checking the source I saw that a workaround might be to add the newline in doRender() method of the Engine class:

        $output = trim($template->render($data)) . PHP_EOL;

What you think?

Post calls not working on PHP 7.1

I Get 404 not found error when calling post functions as below

PHP Deprecated: Non-static method ------ should not be called statically

Did this packages work on PHP 7.1

Did any updates to overcome the issue?

Simple method to set a value for 'supply'

Not sure if I have missed it in the documentation, but I couldn't find a simple method to provide a one line value from one template to another.
For example:
main template:

<title><?php echo $this->supply('title', 'My default title') ?></title>

secondary template:

<?php $this->layout('main') ?>
<?php $this->section('title') ?>My real title for this template<?php $this->stop() ?>

I think there should be a simple one line method to send a value to a supply. I would suggest doing something like this:

  • Change supply to expect for the place where you want to receive a value
  • Use supply to provide a value in one line

With this changes the templates would be:
main template:

<title><?php echo $this->expect('title', 'My default title') ?></title>

secondary template:

<?php $this->layout('main') ?>
<?php $this->supply('title', 'My real title for this template' ?>

I understand this could break backwards compatibility but I think moving forward might be a better naming for both methods.

Regards,

Adrian

0.6.4 is now repeating content sections within a loop

0.6.3 was running perfectly for my code. The item in the loop were iterated properly.
0.6.4 is now just dumping the same first item for every iteration.
all my code stayed the same. I just updated composer.

File: project_item.foil

<?php $this->section('itemsection')?>
<div class="job clearfix pitem" style="page-break-inside: avoid" id="<?=$this->v('project.htmlid','')?>">
    <div class="<?=$this->col1_css ?>">
            <?= $this->insert($this->v('itemlogosectionview','partials/itemlogo_psup')); ?>

           <?php $this->section('projectyearsection')?>
                <div class="year">
                <?=$this->v('project.year','')?>
                </div>
            <?php $this->replace()?>

            <?php $this->section('projectfeessection')?>
                <div class="year">
                <?=$this->v('project.fees')?>
                </div>
            <?php $this->replace()?>
        </div>
    </div>
<?php $this->replace() ?>

The foil above was called from File: body.foil

<?php foreach($this->majorProjects as $project):?>
    <?=$this->insert('partials/project_item',['project' => $project]) ?>
<?php endforeach; ?>

I suspect this change could be the reason, src/Section/Section.php
[https://github.com/FoilPHP/Foil/compare/0.6.3...0.6.4]

if (empty($this->mode)) {
             $this->mode = self::MODE_REPLACE;
         }
-        $this->content = ob_get_clean();
+        $buffer = ob_get_clean();
+        $this->content or $this->content = $buffer;
+        $this->content = ($this->mode & self::MODE_APPEND) ? $buffer.$this->content : $this->content;
         if ($this->mode & self::MODE_OUTPUT) {
             echo $this->content();
         }

Please suggest. Thanks.

Engine option to echo rendered output

Hi, I'd love an engine option to echo the output when you call $this->render() (instead of echo $this->render(). The reason being that it makes things more consistent when used with systems like Slim, where "render" echoes the output on a view.

I can't think of a reason where I'd ever use "render" without echo. I can think of reasons why others might, but echoing seems like it should be the default option. But, for backwards compatibility, being able to drop the echo word would make my code more consistent.

Some issues when creating custom helpers

Hi, I'm registering my helpers like so:

$engine = \Foil\engine($settings);
$engine->registerFilter('translate', function($str) use ($translator) {
    // return $translator->translate($str); // disabled for now until I get the helper working
    return strtoupper($str);
});

Then in my template I have this:

<?php $this->layout('layouts/main') ?>

<?php $this->section('content') ?>
    <p><?= $this->translate('hello_world'); ?></p>
<?php $this->replace() ?>

So registerFilter will receive the callable helper that will be registered. This is how I was doing things with Plates, the second argument can be a callable right? However, when I run the page I get errors. The errors are thrown in Slim, but when I remove the call to the helper the page renders. So I'm wondering if there is something I've done wrong with registering the helper. It seems that some characters are being output to the ob before Slim is ready to do so (although I don't really understand Slim at a deep level, I just var_dump(ob_get_clean()) before line 552 to see it output - string(4) " " - and this is causing (ob_get_length() > 0) to be true, thus causing Slim to throw the RuntimeException. Any suggestions?

[Fri Jun  3 12:20:53 2016] 127.0.0.1:57408 [500]: / - Uncaught exception 'RuntimeException' with message 'Unexpected data in output buffer. Maybe you have characters before an opening <?php tag?' in /var/www/slim_modules/vendor/slim/slim/Slim/App.php:552
Stack trace:
#0 /var/www/slim_modules/vendor/slim/slim/Slim/App.php(344): Slim\App->finalize(Object(MartynBiz\Slim3Controller\Http\Response))
#1 /var/www/slim_modules/vendor/slim/slim/Slim/App.php(298): Slim\App->process(Object(MartynBiz\Slim3Controller\Http\Request), Object(MartynBiz\Slim3Controller\Http\Response))
#2 /var/www/slim_modules/public/index.php(91): Slim\App->run()
#3 {main}
  thrown in /var/www/slim_modules/vendor/slim/slim/Slim/App.php on line 552

Add 'strict_variables' option to make Foil thrown exception when a required variable is missing

In #4 @skyosev proposed a 'strict_variables' option (similar to Twig one) that would be useful in development context.

My first thoughts is to add it and support 3 values:

  • true -> thrown an Exception when a required var is not defined
  • false -> resolve undefined vars as empty strings (current and default behavior)
  • "notice" -> thrown a notice when a required var is not defined and resolve to empty string. This way it can be ignored using proper error_reporting setting.

Double render issue

Hi, I found a strange bug when the ->render() function is executed twice (or more) in the same script.
Let's say you have this directory structure:

index.php
templates/base.php
templates/page.php

With this content in each file:
index.php

<?php

require 'vendor/autoload.php';

$engine = Foil\engine([
  'folders' => ['templates']
]);

$page1 = $engine->render('page');

$page2 = $engine->render('page');

echo $page2;

templates/base.php

<?php $this->section('content') ?>
BASE CONTENT
<?php $this->stop() ?>

templates/page.php

<?php
$this->layout('base');

if you execute the index.php script, for instance, by command line: php index.php, this is the output obtained:

BASE CONTENT

BASE CONTENT`

I.e. the 'content' section appears twice! When it should be only one line, isn't it?
This is accumulative, if you have 3 ->render() calls, you can expect 3 repetitions of the section.

Do you have a clue of why is this happening?
Thanks

Retrieve Data Inside Templates: loops

Can you use helpers for echoing variables while iterating through an array? All I have been able to do is something like this:

<?php foreach ($this->news_stories as $story): ?>
  <li><?= $story['title'] ?></li>
<?php endforeach ?>

Are there any other options for doing this?I'm not sure whether this is providing an escaping or other benefits of helpers.

Removing the $this Context From Templates

Hi Giuseppe,

This isn't an issue, just a question.

I have an existing framework that uses the output buffer to load up and render templates, and I'd like to replace that with Foil, but I can't seem to get my existing variables to render because they don't use the $this context.

For instance in my controller I set all my variables into the $data array:

$data['products'] = $products;
$data['menu']     = $this->theme->controller('widget/header_menu');

Then push the $data variable to the view class (almost exactly the way you do in Foil.)

return $this->theme->view('content/header', $data);

In my View class, the data is extracted with the file, into the buffer, then sent to the user.

if (is_readable($this->file)):
    extract($this->data);
    ob_start();
    require $this->file;
    $output = ob_get_contents();
    ob_end_clean();

    return $output;
endif;

So my templates simply reference the name of the variable without the $this context:

<?php foreach($products as $product): ?>
     // do something with $product
<?php endforeach; ?>

<?= $menu; ?>

etc.

So what I'm asking I guess, is there any way to push my data to a Foil instance so that I don't have to edit all the templates.

I have over 500 templates, and my client isn't going to wait to have all those templates re-written.

Thanks for your help, great job on Foil, I hope it'll work for me.

--Vince

Argument 1 passed to Foil\\Engine::__construct() must be an instance of Foil\\Template\\Stack, array given

Hi Giuseppe,

When I instantiate engine as follows:

        $engine = new \Foil\Engine([
            'folders' => 'ui/default',
            'ext' => 'phtml'
        ]);

I get the following error:

[:error] [pid 6538] [client 127.0.0.1:43919] PHP Catchable fatal error:  Argument 1 passed to Foil\\Engine::__construct() must be an instance of Foil\\Template\\Stack, array given, called in /home/bronx/www/clubman/index.php on line 73 and defined in /home/bronx/www/clubman/vendor/foil/foil/src/Engine.php on line 30

I'm running this PHP version:

PHP 5.5.12-2ubuntu4.2 (cli) (built: Feb 13 2015 18:56:49) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies

By the way: your blog about Plate sounds familiar ... I had the same problems as you and when I started to search for a replacement I stumbled on your wonderful project. Keep up the good work!

Franky

is not a valid template name

Why happen this, sometimes

RuntimeException: [route/to/page] is not a valid template name.
at Foil.Engine.render(Engine.php:214)
at Foil.Template.Template.insert(Template.php:188)
at require(default.php:14)
at Foil.Template.Template.collect(Template.php:287)
at Foil.Template.Template.render(Template.php:231)
at Foil.Engine.doRender(Engine.php:307)
at Foil.Engine.render(Engine.php:211)
at Goteo.Application.View.render(View.php:55)
at Goteo.Core.Controller.viewResponse(Controller.php:29)
at Goteo.Controller.AdminController.indexAction(AdminController.php:188)
at call_user_func_array(Unknown Source)
at Symfony.Component.HttpKernel.HttpKernel.handleRaw(HttpKernel.php:144)
at Symfony.Component.HttpKernel.HttpKernel.handle(HttpKernel.php:64)
at Goteo.Application.App.run(App.php:179)
at (main)(index.php:43)

Fatal error with $this->insert('mypartial')

I tried to insert a partial, but recieved
Fatal error: Uncaught exception 'LogicException' with message '"start" is not a registered Foil callback

I have the following files:

partial.php
<?php
require 'vendor/autoload.php';
$foil = Foil\Foil::boot([
    'folders' => [ 
        'templates',
        'partials' 
         ],
    'html_tags_functions' => true
]);
$engine = $foil->engine();
echo $engine->render('partial_temp');
?>

The templates/partial_temp.php file

<?php $this->layout('partial_layout') ?>
<?php $this->section('partial') ?>
        <?= $this->insert('the_partial') ?>
<?php $this->append() ?>

This is partials/the_partial.php i want to insert:

<?php $this->start('the_partial') ?>
    <div>
  <?= $this->html('img','images/image1.jpg', ['id' => 'uid']) ?>
    </div>
<?php $this->stop() ?>

The template is based on a simple /template/partial_layout.php

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <div id="partial">
          <?php $this->section('partial') ?>
              <div id="some_div">
              </div>
          <?php $this->append() ?>
        </div>
    </body>
</html>

What is going wrong?
A little help is much appreciated,
thanks in advance.

Trimming output?

Hi!

Thanks for creating Foil. It solves a big issue I had with Plates: lack of multi-folder support and so creating skinnable templates with Plates was not possible.

One thing with Foil that keeps biting me is this line which is:

    private function doRender($path, array $data = [], $class = null)
    {
        // ...
        $output = trim($template->render($data));
        // ...
        return $output;
    }

Why trim()? Can this not be left up to the developer as desired? E.g. me! Or made an option? One of things we use foil for (as well as HTML templates) is building plain text configuration files and whitespace is important here.

Thanks, Barry.

Duplicate code with nested sections

I have the following setup:
The layout defines sections:

<!DOCTYPE html>
<html>
<head>
    <title><?= $this->e('title') ?></title>
    <?php $this->section('head'); $this->stop(); ?>
</head>
<body>

<?php $this->section('content');$this->stop(); ?>

<?php $this->section('end-body');$this->stop(); ?>
</body>
</html>

Then there is the template appending some content to the content section of the layout. Some of the content is loaded by including a partial:

<?php $this->layout('layout::page', ['title' => 'Page title']) ?>

<?php $this->section('content') ?>
<h1>Test</h1>

<?= $this->insert('partials::date-input'); ?>
<?php $this->append() ?>

The partial references a JS file (which should be appended to the "end-body" section of the layout) and some HTML which should be inserted whereever $this->insert('partial-name') is called.

<?php $this->section('end-body') ?>
<script src="/jquery.min.js"></script>
<script src="/intercooler.js"></script>
<?php $this->append() ?>

<div ic-get-from="<url>" ic-trigger-on="scrolled-into-view"></div>

The result is:

<!DOCTYPE html>
<html>
<head>
    <title>Page title</title>
    </head>
<body>

<h1>Test</h1>

<script src="/jquery.min.js"></script>
<script src="/intercooler.js"></script>

<div ic-get-from="<url>" ic-trigger-on="scrolled-into-view"></div>

<script src="/jquery.min.js"></script>
<script src="/intercooler.js"></script>
</body>
</html>

So the JS files get embedded twice.
I am quite sure that I did something wrong but perhaps this really is a bug.

Development roadmap

Hey @gmazzap. I mentioned you in another WP framework project and in connection was wondering what the status of this templating project is. Feature complete? 0.7 coming some time or too busy? Did someone else produce something even better?

Question about template variables

Hi again!

I'm curious about the need to use $this->my_var while accessing data in templates. Is there any particular reason (performance, escaping etc.) for not using locally scoped variables like $my_var ? Plates does allow it AFAIK.

I didn't dig into Foil that much, so my question could sound improper.

Regards,
Stoyan

`supply()` template method does not work when same engine instance is used to render more templates

As per the title, here is my use case.

/views/layouts/master.php

<!DOCTYPE html>
<html>
    <head>
        <title><?= $T->v('title', 'Foo Bar') ?></title>
    </head>
    <body>
        <main><?= $T->supply('main') ?></main>
    </body>
</html>

/views/default.php

<?php $T->layout('layouts/master') ?>

<?php $T->section('main') ?>

    <h1>Something</h1>

<?php $T->stop() ?>

This next bit is overly simplified, I am running a PHP-DI container inside a Wordpress theme with a PSR-7 router. But none of that should matter (I don't think).

$engine = Foil::boot(['folders' => ['/views'], 'alias'   => 'T'])->engine();
$html = $engine->render('default');

The Result:

<!DOCTYPE html>
<html>
    <head>
        <title>Foo Bar</title>
    </head>
    <body>
        <main></main>
    </body>
</html>

Expected Result:

<!DOCTYPE html>
<html>
    <head>
        <title>Foo Bar</title>
    </head>
    <body>
        <main><h1>Something</h1></main>
    </body>
</html>

If I modify the master layout to look like this, I get the expected result:

<!DOCTYPE html>
<html>
    <head>
        <title><?= $T->v('title', 'Foo Bar') ?></title>
    </head>
    <body>
        <main>
            <?php $T->section('main') ?>
            <?php $T->stop() ?>
        </main>
    </body>
</html>

The issue appears to be here:
https://github.com/FoilPHP/Foil/blob/master/src/Template/Template.php#L172

$this->sections is empty. I have tried to follow how the sections are defined and added to the stack but between dependency injection, events, magic methods & the fact it's now 20mins past midnight. I got confused rather quickly. I will have another look in the morning with fresh eyes.

All the same the supply method certainly doesn't appear to work or at least it doesn't work exactly like the Laravel Blade @yield syntax. Maybe I am missing something obvious??? I'll probably discover my error the second I hit the "Submit new issue" button.

Multiple section replace don't work

Hi Giuseppe,
I've created a simple demo for, apparently, a bug I have found.

I have a base template called: baseTemplate

<!DOCTYPE HTML>
<html>
	<head>
	</head>
    <body>
	<? $this->section('body') ?>aaa<? $this->stop() ?>
    </body>
</html>

I have a second template called: templateA

<? $this->layout('_layout/baseTemplate') ?>
<? $this->section('body') ?>bbb<? $this->replace() ?>

I have a third template called: templateB

<? $this->layout('_layout/templateA') ?>
<? $this->section('body') ?>ccc<? $this->replace() ?>

While the result is supposed to be: ccc, in fact, it shows bbb

If I change the the section ending in templateA from replace() to stop(), I get ccc.

I would we very thankful if you could take a look at it, and fix it. :)
Yoshi.

Prepend directories in the finder

In some situations would be nice to have a method to "prepend" a folder to the current list of search folders.
Example, let's say you have this 2 folders where to search for templates:

$engine->addFolder('/templates/main_folder');
$engine->addFolder('/templates/sub_folder');

templates will be search firts in the folder 'main' and then, if not found, in "sub".
what about if you want to add a folder in the beginning AFTER the initialization?
That will be a nice improvements to add flexibility.

Something like:

$engine->prependFolder('/templates/plugin_folder');

By the way, outstanding work in this project! thanks a lot!

Documentation error

Hi Giussepe, I have just found your library and so far it looks great ! I will start using it in my new projects.
Right now I am trying to get familiar with it and I found a little mistake in the documentation of the Supply method.
Where it says: supply('posts', 'Sorry, no post found.') ?>
It should say : supply('posts', 'Sorry, no post found.') ?>
Otherwise the default value would never be written.
Regards and keep the good work !

Code in overwritten sections runs

I guess this is unavoidable due to the fact that template files are simply required if I got that right from looking at the code.

When inheriting a couple of times this does run quite a lot of unnecessary stuff. Of course if you have clean templates free of any logic and expensive code this shouldn't matter. ๐Ÿ˜‰

Thinking about it what if you had a simple helper exposed to the templates that tells a template if a certain section is overwritten by child templates to optionally skip a certain part of the template when optimisation makes sense. Haven't thought this through though.

$engine->renderSection()?

Hi, Foil seems great, i'm evaluating it for a project instead of Plates,
but i can't find a way to render specific sections programmatically,
also Plates does not support this, but Twig does.

It's useful for email templates where you can have a template with 3 different sections:

  • subject
  • body_html
  • body_text

is possible to add a function like:

$subject = $engine->renderSection('email-template','subject-section', $some_data);
$body_html = $engine->renderSection('email-template','body-html-section', $some_data);
$body_text = $engine->renderSection('email-template','body-text-section', $some_data);

and/or have something like:

$tpl = $engine->getTemplate('email-template');
$tpl->setData($some_data);
$subject = $tpl->renderSection('subject-section');
$body_html = $tpl->renderSection('body-html-section');
$text_html = $tpl->renderSection('body-text-section');

email-template.php:

<?php
$this->section('subject-section') ?>
TEST SUBJECT
<?php $this->stop() ?>
<?php $this->section('body-html-section') ?>
TEST HTML BODY
<?php $this->stop() ?>
<?php $this->section('body-text-section') ?>
TEST TEXT BODY
<?php $this->stop() ?>

eventually if the requested section does not exists renderSection() will simply return null

what do you think?

thanks in advice!

Option to not arraize some data

Would you consider adding the option to keep some objects as they are? Because when having a complex nested array of data where everything except some certain type of data needs to be arraized this would be really handy.

My first idea would be to just use the existing transformer parameter. If the value is false just skip the arraization and keep the object:

$arraized = $Foil\arraize($products, true, ['My\App\Product'=> false]);

I wouldn't be surprised though if you said wontfix as this breaks the basic assumption that

whatever data you pass to the function at the end of the process, you get an array that contains no objects

Just asking... ๐Ÿ˜‰

problem with __toString()

class One {
public __toString() {
return "One";
}
public hey() {
return "Hey";
}
}

$engine->useData([
'one' => new One()
])

//a-tpl.php

one->hey(); ?>

foil will convert object with method "__toString" to string.

Rendering stops after 2nd double quote

I apologise in advance if this is a daft question, I'm new to both PHP and Foil.

I have the following code within a template:

screenshot

My problem is that the rendering seems to stop after the 2nd double quote is encountered, i.e. I do not get all the table column headers returned. Please can you confirm what I am doing wrong?

Thanks very much for your time and thanks for Foil as well...very impressive! I was going to use Plates until I came across your blog post. Keep up the good work.

PHP Warning: htmlspecialchars()

I see a lot of warnings after upgrading to Foil 0.4.1 :

[Fri Apr 24 20:59:07.155292 2015] [:error] [pid 5704] [client 127.0.0.1:49545] PHP Warning: htmlspecialchars() expects parameter 1 to be string, array given in /home/bronx/www/clubman/vendor/aura/html/src/Escaper/HtmlEscaper.php on line 77

SectionInterface::MODE_REPLACE causes child template inheritance to fail

Here's a simplified version of my setup:

<!-- layout.php -->
<html><head><etc /></head><body>
<?php $this->section('content'); ?>
  <h1>Output some html</h1>
<?php $this->stop();
<?= $this->buffer() ?>
// yadda yadda ?>
</body></html>

<!-- child.php -->
<?php $this->layout('layout'); ?>
<?= $this->buffer() ?>

<!-- page.php -->
<?php $this->layout('child'); ?>
Stuff outside sections.
<?php $this->section('content'); ?>
Some additional stuff
<?php $this->append(); ?>

With 'section_def_mode' => Foil\Contracts\SectionInterface::MODE_REPLACE, the content section is neither appended NOR replaced. Every "referenced" section doesn't work, but other content from page.php is output correctly.

Commenting out the MODE_REPLACE restored section inheritance into the page.

looping over imported template with a section defination

I did a loop (there is no internal loop support, I had to use standard php foreach) and inside the loop I imported by small template. That small template had many sections defined. The content of these sections got exponentially bigger and repeated by every iteration in the final rendered html.

I think, Foil does not understand loops, so it keep the html generated from section of last iteration and keep appending over it. What outputs is like:

  • header
  • imported_section_1
  • imported_section_1
  • imported_section_2
  • imported_section_1
  • imported_section_2
  • imported_section_3
  • footer

when the output should have been

  • header
  • imported_section_1
  • imported_section_2
  • imported_section_3
  • footer

How to fix this behavior?

Markdown Block

About to start work on a custom block that parses Markdown.
A little surprised no one has not done this yet???

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.