Skip to content

Conversation

@michalsn
Copy link
Owner

This PR fixes view fragments:

  • handling multiple fragments with the same name
  • fragments now respect sections

Closes #75

/**
* Whether we should display fragments tags or not.
*/
protected function showFragments(bool $display = true): RendererInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not self or static?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I wanted to follow the current convention used in the original View class: https://github.com/codeigniter4/CodeIgniter4/blob/develop/system/View/View.php

Copy link
Contributor

Choose a reason for hiding this comment

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

Good. This is a notification in the IDE

@neznaika0
Copy link
Contributor

neznaika0 commented Oct 13, 2024

Everything is fine for multi-fragments.
I'll check on the project later. I have a problem with flash messages working.

After the request, you need to return the template and toasts from the flash for it. There was no data before PR, we need to review it again.

Will the clarification of the work be indicated in the documentation?

Fragments, like sections, are complemented, that is, by specifying several fragments of the same name, they will be displayed as one. But the input data for them may differ depending on the order of output.

$this->assertSame($expected, $result);
}

public function testHugeView(): void
Copy link
Contributor

Choose a reason for hiding this comment

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

By adding a test for view(), the result is not obvious - the layout inside the section. Is this a problem with the parent view() ?

    public function testHugeViewFragment(): void
    {
        $result = view_fragment('huge/view', ['fragment_one']);

        $expected = <<<'EOD'
            Fragment one (from "huge/view")
            Fragment one (from "huge/include")
            Fragment one (from "huge/layout")

            EOD;

        $this->assertSame($expected, $result);
    }

    public function testHugeView(): void
    {
        $result = view('huge/view');

        $expected = <<<'EOD'


            View top

            Fragment one (from "huge/view")

            # include start in "huge/view"
            Layout top

            Section (from "huge/view")

            Include top

            Fragment one (from "huge/include")

            Include bottom

            Fragment one (from "huge/layout")

            Layout bottom
            # include end in "huge/view"

            View bottom

            EOD;

        $this->assertSame($expected, $result);
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, bug framework

Copy link
Owner Author

Choose a reason for hiding this comment

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

If you place the content outside the section this is what you will get. I don't see any issues here.

/**
* Whether we should display fragments tags or not.
*/
protected function showFragments(bool $display = true): RendererInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

Good. This is a notification in the IDE

@michalsn michalsn merged commit 8ac11f8 into develop Oct 17, 2024
14 checks passed
@michalsn michalsn deleted the fix/view_fragments branch October 17, 2024 08:35
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.

Template viewData not inherited

3 participants