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

DOC Document changes to template layer #591

Merged

Conversation

GuySartorelli
Copy link
Member

@GuySartorelli GuySartorelli marked this pull request as draft September 26, 2024 04:27
@GuySartorelli GuySartorelli force-pushed the pulls/6/refactor-template-layer branch 3 times, most recently from 94d90fe to 827cb70 Compare October 4, 2024 00:21
@GuySartorelli GuySartorelli force-pushed the pulls/6/refactor-template-layer branch 8 times, most recently from a6f45e5 to fd791b5 Compare October 14, 2024 02:57
@GuySartorelli GuySartorelli marked this pull request as ready for review October 23, 2024 02:37

Just like in PHP, method names are case insensitive, but property names are case sensitive.

Using `$MyValue` in a template will successfully call a `myValue()` method, or a `getMyvalue()` method even though the case doesn't match what you used in the template. But it *will not* match a `myValue` property or database field because the case doesn't match.
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
Using `$MyValue` in a template will successfully call a `myValue()` method, or a `getMyvalue()` method even though the case doesn't match what you used in the template. But it *will not* match a `myValue` property or database field because the case doesn't match.
Using `$MyValue` in a template will successfully call a `myValue()` method, or a `getMyValue()` method even though the case doesn't match what you used in the template. But it *will not* match a `myValue` property or database field because the case doesn't match.

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 (found an unrelated method with the same bad casing in php coding conventions which I also updated)

@@ -459,6 +459,62 @@ Note that the `SilverStripe\View\ViewableData` class has been renamed to [`Silve

See [many renamed classes](#renamed-classes) for more information about this change.

#### Improved separation between the view and model layers {#view-layer-separation}

Historically the `ModelData` class did double-duty as being the base class for most models as well as being the presumed class wrapping data for the template layer. Part of this included methods like `XML_val()` being called on any object in the template layer, despite being methods very specifically implemented on `ModelData`.
Copy link
Member

Choose a reason for hiding this comment

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

Historically it's been called ViewableData ? Maybe mention that ModelData used to be called ViewableData

Copy link
Member Author

Choose a reason for hiding this comment

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

Directly above this it says

Note that the SilverStripe\View\ViewableData class has been renamed to SilverStripe\Model\ModelData. We will refer to it as ModelData in the rest of these change logs.

@@ -6,6 +6,9 @@ icon: code

# Rendering data to a template

> [!NOTE]
> The template syntax, file extensions, and specifics about which tempaltes are chosen from a set as described on this page are specific to the default [`SSTemplateEngine`](api:SilverStripe\View\SSTemplateEngine) - but many of the concepts here (especially the PHP code) should work with any template engine you choose to use.
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
> The template syntax, file extensions, and specifics about which tempaltes are chosen from a set as described on this page are specific to the default [`SSTemplateEngine`](api:SilverStripe\View\SSTemplateEngine) - but many of the concepts here (especially the PHP code) should work with any template engine you choose to use.
> The template syntax, file extensions, and specifics about which templates are chosen from a set as described on this page are specific to the default [`SSTemplateEngine`](api:SilverStripe\View\SSTemplateEngine) - but many of the concepts here (especially the PHP code) should work with any template engine you choose to use.

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

@@ -194,5 +203,62 @@ class MyPageController extends PageController
}
```

> [!WARNING]
> A common mistake is trying to loop over an array directly in a template - this won't work. You'll need to wrap the array in some `ModelData` instance as mentioned above.
Or wrap the data in a `ModelData` subclass:
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
Or wrap the data in a `ModelData` subclass:
Or wrap the data in a `ModelData` subclass such as `ArrayList`:

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, but said ArrayData since that's what the example shows.


Every time a raw template file is processed, some PHP code is generated from it which is then executed to produce the final rendered result.

That PHP code is stored in the filesystem so that the raw template file doesn't need to be processed again until either the cache is flushed or the raw template file is updated.
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
That PHP code is stored in the filesystem so that the raw template file doesn't need to be processed again until either the cache is flushed or the raw template file is updated.
That PHP code is cached in the filesystem so that the raw template file doesn't need to be processed again until either the cache is flushed or the raw template file is updated.

Copy link
Member

Choose a reason for hiding this comment

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

Just ties it together a little better

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

@emteknetnz emteknetnz merged commit 9f14ed6 into silverstripe:6 Oct 30, 2024
3 checks passed
@emteknetnz emteknetnz deleted the pulls/6/refactor-template-layer branch October 30, 2024 21:54
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