Skip to content

Added sections inheritance of fetched templates while retaining mutation mode#310

Closed
Abdillah wants to merge 9 commits into
thephpleague:v3from
Abdillah:feature/section-inheritance
Closed

Added sections inheritance of fetched templates while retaining mutation mode#310
Abdillah wants to merge 9 commits into
thephpleague:v3from
Abdillah:feature/section-inheritance

Conversation

@Abdillah
Copy link
Copy Markdown

Based on #306, implements section as history of mutation. There is an uncertainty in my implementation details: whether to allow multiple mutation with Template::SECTION_MODE_REWRITE mode or just break at the first attempt or some other alternative behavior.

Comment thread src/Template/TemplateSection.php Outdated
throw new \InvalidArgumentException("Only same section may be merged");
}

$this->mutationlog = array_merge($this->mutationlog, $other->mutationlog);
Copy link
Copy Markdown
Author

@Abdillah Abdillah Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still unsure on what to do if multiple rewrites exist, some in the right mutationlog. If we simply merge, the operation on $this->mutationlog will be lost even if APPEND and PREPEND exists.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking of grouping REWRITE before any mutation. That is consistent with what template system should do in my mind.

layout.php

<?php $this->section('javascript') ?>

page.php

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

<?php $this->start('javascript') ?>
  <script src="base-page-script-very-light-weight.js"></script>
<?php $this->end() ?>

<?= $this->fetch('common-component-a') ?>
<?= $this->fetch('heavyweight-component-b') ?>

heavyweight-component-b.php

<?php $this->start('javascript') ?>
  <script src="base-page-script-support-heavy-weight.js"></script>
<?php $this->end() ?>

common-component-a.php

<?php $this->push('javascript') ?>
  <script src="common-component-a.js"></script>
<?php $this->end() ?>

The end result will be,

<script src="base-page-script-support-heavy-weight.js"></script>
<script src="common-component-a.js"></script>

@Abdillah Abdillah closed this by deleting the head repository Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants