Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple method to set a value for 'supply' #20

Closed
adrian-e opened this issue Jul 8, 2015 · 2 comments
Closed

Simple method to set a value for 'supply' #20

adrian-e opened this issue Jul 8, 2015 · 2 comments

Comments

@adrian-e
Copy link

adrian-e commented Jul 8, 2015

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

@gmazzap
Copy link
Contributor

gmazzap commented Jul 8, 2015

Hi Adrian,

thanks for your interst and for your suggestion.

First of all, you are probably right about supply not being a good name.

Problem is that I wanted to port the Lavarel Blade yield feature.

Problem is that yield can't be used because is a PHP reserved keyword, so I opted for supply, you know, I am not a native English speaker and probably that was not a good synonymous...

However, changing name of templates method is something I really want to avoid.

If someone had already used Foil (I swear I had), a change like this means change any template ever wrote in any project.

Considering that one may have quite a lot templates (and layouts, and partials...) on every project, upgrading to the version introduce this change in all projects would mean change hundreds of template files, and in each file possibly multiple instances of supply... Sorry, but no.

Moreover, layout and templates should not work like that.

A layout is intended to be... a layout, i.e. defines sections of the page to be filled.

A line of text is more a variable than a section. So it's best served via render() method, or (that's possibly the solution you're looking for) via layout data:

In layout

<title><?= $this->v('title', 'My Default Title') ?></title>

In template

<?php $this->layout('main', ['title' => 'My Custom Title']) ?>

@gmazzap gmazzap closed this as completed Jul 8, 2015
@adrian-e
Copy link
Author

adrian-e commented Jul 9, 2015

You are completely right ! I will use variables as you suggest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants