phproad / phpr-module-cms

[PHPR Module] Content Management System
4 stars 1 forks source link

More head_ blocks. #3

Closed Garbee closed 11 years ago

Garbee commented 11 years ago

We should have separate CSS and JS head declaration blocks for greater performance.

Right now pages have one head_declarations block. This is fine for meta details and things that don't impact performance. But if someone wants to include some CSS and JS (that depends upon jquery) for a specific page then the best place for that to be rendered is after the main JS in the head. However, that can then add CSS after the JS which could cause FOUC for instance. Being able to declare CSS and JS separately along with misc head info will mean the fastest and most reliable front-end performance for those that chose to take advantage of it.

Thoughts? Think I'm insane? Agree?

highruned commented 11 years ago

Yes, but, we should implement yields (3.2) instead.

To work with PHP and match PHPR, I suggest: yield -> get_content_for content_for -> start/end_content_for

start_content_for starts output bufferring end_content_for stops the buffer display_content dumps the collective buffers from all pages/partials (this means that cms objects need to be loaded to gather the block names, then pages/partials/pre/post blocks need to be executed, then need to be executed again for real).

<?= $this->get_content_for('head_styles') ?>
<?= $this->get_content_for('head_scripts') ?>
<? $this->start_content_for('head_styles') ?>
  <style>body { color: orange; }</style>
<? $this->end_content_for('head_scripts') ?>
<? $this->start_content_for('head_scripts') ?>
  <script>alert('orange!');</script>
<? $this->end_content_for('head_scripts') ?>

These content blocks should stack together from multiple sources (cms objects).

highruned commented 11 years ago

Implemented and coming. Usage:

Set:

<? $this->start_content_for('breadcrumb') ?>
    <ul class="breadcrumb">
        <li>You are here: </li>
        <li><a href="<?= root_url() ?>"><?= c('site_name') ?></a> <span class="divider">/</span></li>
        <li><a href="<?= root_url('projects') ?>">Projects</a> <span class="divider">/</span></li>
        <li class="active"><?= $project->title ?></li>
    </ul>
<? $this->end_content_for('breadcrumb') ?>

Get:

<?= $this->get_content_for('breadcrumb') ?>
highruned commented 11 years ago

When this comes down, you should be good to create as many blocks as you want.

Garbee commented 11 years ago

This looks really nice and is a much better way to handle it. But, for the lazy can we still do <?= $this->display_head() ?> and have it pull what is there in? Although, we could drop that entirely in order to try and enforce best practices (although if people don't care they should be able to quickly do display_head().)

highruned commented 11 years ago

display_head will still exist, but I think if you want to split out the styles and scripts to avoid FUOC and performance, you are in the minority that can now use get_content_for.

highruned commented 11 years ago

Looks like Sam added yield blocks. Good enough to close this ticket, Garbee?

Garbee commented 11 years ago

I haven't tested but it does look fine. I'll test the next time I'm able to get a new install since I'm not messing with my current one. ;)

Thanks!