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

V4 Block Func #175

Closed
ragboyjr opened this issue Nov 29, 2017 · 9 comments
Closed

V4 Block Func #175

ragboyjr opened this issue Nov 29, 2017 · 9 comments
Assignees
Milestone

Comments

@ragboyjr
Copy link
Contributor

ragboyjr commented Nov 29, 2017

Add a block func that will allow the following semantics:

<?php $v->block('section-name') ?>
// define the default block here
<?php $v->end() ?>

If the section exists, it should echo the section content and discard the content from the end callback. If it does not exist, it should output the contents from the end callback.

This maybe depends on #177

A different alternative is to use an if statement. This is more verbose, but allows us to not even buffer the default content if we don't want to.

<?php if ($v->block('section-name')): ?>
// define the default block content here
<?php endif; ?>

In this scenario, the block func simply echos the section content and returns false it exists, or just returns true.

@ragboyjr ragboyjr added this to the 4.0 milestone Nov 29, 2017
@ragboyjr ragboyjr mentioned this issue Nov 29, 2017
3 tasks
@ragboyjr
Copy link
Contributor Author

@ragboyjr
Copy link
Contributor Author

Would very much like other opinions on this one to see what the community would prefer.

@ragboyjr
Copy link
Contributor Author

@velosipedist @gmazzap What do you think about this syntax?

@ragboyjr
Copy link
Contributor Author

ragboyjr commented Dec 5, 2017

I'm leaning towards the if block syntax.

ragboyjr added a commit that referenced this issue Dec 5, 2017
- Added more tests
- Removed the compose func since it's not used

Signed-off-by: RJ Garcia <[email protected]>
@carbontwelve
Copy link
Contributor

Not that it carry's much weight but my personal opinion is that the if block syntax makes sense; however I do read if ($v->block('section-name')): as if block with name 'section-name' exists display default text.

@ragboyjr
Copy link
Contributor Author

ragboyjr commented Dec 5, 2017

Hmm, interesting point. maybe if (!$v->block('section-name')):?

@carbontwelve

I was trying to save on characters, and i was worried people would omit the ! and end up having both options displayed.

But i'm not sold on either way. Just need feedback from the community to see what makes the most sense.

@ragboyjr
Copy link
Contributor Author

ragboyjr commented Dec 5, 2017

If use the block/end syntax, there would be no ambiguity like you mention; however, we'd have to needlessly process everything in the if block.

@ragboyjr
Copy link
Contributor Author

ragboyjr commented Dec 5, 2017

Maybe we could come up with a way that everything between block and end is lazily evaluated.

ragboyjr added a commit that referenced this issue Dec 5, 2017
ragboyjr added a commit that referenced this issue Jan 26, 2018
- Added ability for else parts in sections
- It supports stringables and closures for
  lazy evaluation

Signed-off-by: RJ Garcia <[email protected]>
ragboyjr added a commit that referenced this issue Jan 26, 2018
- Added ability for else parts in sections
- It supports stringables and closures for
  lazy evaluation
- Created obWrap utility to wrap a closure and
  error handling with output buffering

Signed-off-by: RJ Garcia <[email protected]>
ragboyjr added a commit that referenced this issue Jan 26, 2018
@ragboyjr
Copy link
Contributor Author

ragboyjr commented Jan 26, 2018

I ended up going with just a second parameter to the section func instead of adding a new one. I felt like it was confusing to have two functions that do the same thing, and the if statement part was a little weird.

The new syntax allows a closure to be passed in as the second parameter which is lazily evaluated.

        <?=$v->section('meta', function() { ?>
        <meta charset="UTF-8"/>
        <?php }); ?>

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