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

API Refactor template layer #11405

Merged

Conversation

GuySartorelli
Copy link
Member

Includes the following large-scale changes:

  • Impoved barrier between model and view layers
  • Improved casting of scalar to relevant DBField types
  • Improved capabilities for rendering arbitrary data in templates

Issue

@GuySartorelli GuySartorelli marked this pull request as draft September 26, 2024 04:22
@GuySartorelli GuySartorelli force-pushed the pulls/6/refactor-template-layer branch 3 times, most recently from 649a6fc to da2ebdc Compare September 27, 2024 02:34
@GuySartorelli GuySartorelli marked this pull request as ready for review September 27, 2024 02:37
@GuySartorelli GuySartorelli marked this pull request as draft September 27, 2024 02:37
@GuySartorelli GuySartorelli force-pushed the pulls/6/refactor-template-layer branch 15 times, most recently from 2b00a05 to fff294a Compare October 2, 2024 03:20
@GuySartorelli GuySartorelli force-pushed the pulls/6/refactor-template-layer branch from fff294a to ad22082 Compare October 2, 2024 03:47
Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

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

Need to update commit message / PR title

src/Forms/TreeDropdownField.php Show resolved Hide resolved
src/Model/ModelData.php Show resolved Hide resolved
src/Model/ModelData.php Outdated Show resolved Hide resolved
src/Model/ModelData.php Show resolved Hide resolved
src/View/ViewLayerData.php Show resolved Hide resolved
src/Model/ModelData.php Show resolved Hide resolved
src/Model/ModelDataCustomised.php Outdated Show resolved Hide resolved
src/View/CastingService.php Show resolved Hide resolved

public function __get(string $name): ?ViewLayerData
{
$value = $this->getRawDataValue($name, type: ViewLayerData::TYPE_PROPERTY);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$value = $this->getRawDataValue($name, type: ViewLayerData::TYPE_PROPERTY);
$value = $this->getRawDataValue($name);

Copy link
Member Author

Choose a reason for hiding this comment

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

Discussion about this can be in #11405 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


public function __call(string $name, array $arguments = []): ?ViewLayerData
{
$value = $this->getRawDataValue($name, $arguments, ViewLayerData::TYPE_METHOD);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$value = $this->getRawDataValue($name, $arguments, ViewLayerData::TYPE_METHOD);
$value = $this->getRawDataValue($name, $arguments);

Copy link
Member Author

Choose a reason for hiding this comment

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

Discussion about this can be in #11405 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@GuySartorelli GuySartorelli force-pushed the pulls/6/refactor-template-layer branch 3 times, most recently from 59730f2 to 063628a Compare October 30, 2024 00:47
Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

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

Things looking good, this is mostly likely an issue at my end

I've tried copying https://github.com/GuySartorelli/silverstripe-twig to my local (I copied files, rather than using composer), and by adding the following line to TwigTemplateEngine::render() if (!$this->template) return ''; (this is so that it's tolerant of missing Something.twig files)

I was able to get the "global" method described in the twig module readme to work i.e. setting yml, and I was also about to get the controller method to work, by updating PageController, though I wasn't able to get the Model version to work by updating Page

I get that it's a highly experimental module, though I just need to double check with you that the ModelData::renderWith() is actually behaving as expected

// app/src/Page.php

    public function renderWith($template, ModelData|array $customFields = []): DBHTMLText
    {
        // $template = SSViewer::create($template, SSTemplateEngine::create());
        $template = SSViewer::create($template, TwigTemplateEngine::create());
        return parent::renderWith($template, $customFields);
    }

@GuySartorelli
Copy link
Member Author

Yup, that works.
You need to explicitly render a page in a template (you're rendering the controller normally) with something like this (assuming the page has at least one child page):

<% loop $AllChildren %>
  $Me
<% end_loop %>

Alternatively, use something that isn't a page.

Includes the following large-scale changes:
- Impoved barrier between model and view layers
- Improved casting of scalar to relevant DBField types
- Improved capabilities for rendering arbitrary data in templates
@GuySartorelli
Copy link
Member Author

Just realised I didn't update the commit message per #11405 (review)
Done now. Won't redo sink since all I changed was the commit message.

@GuySartorelli GuySartorelli force-pushed the pulls/6/refactor-template-layer branch from 063628a to 11a4b60 Compare October 30, 2024 20:15
@GuySartorelli GuySartorelli changed the title API Refactor template layer into its own module API Refactor template layer Oct 30, 2024
@emteknetnz emteknetnz merged commit 6b33b5a into silverstripe:6 Oct 30, 2024
8 of 10 checks passed
@emteknetnz emteknetnz deleted the pulls/6/refactor-template-layer branch October 30, 2024 21:47
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