-
Notifications
You must be signed in to change notification settings - Fork 90
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
Centralized conditional RockerContent rendering ? #134
Comments
I don't think some of your examples aren't valid rocker templates, I'm
guessing you missed some syntax? I'm also actually having a tough time
following which is what in your examples and why you'd need an @if in
everything. If you simply consolidate your logic into a single template
you call from the others, not sure why you think you need conditional logic
everywhere. If you can consolidate your examples into something a little
easier to follow, with exact syntax, happy to help.
…On Thu, Feb 27, 2020 at 1:59 AM albert-kam ***@***.***> wrote:
I am having a common situation where a page template is using a common
layout template for generating a html page.
The page template example:
@Args(MyObj obj, MyError error)
@Rocker.template(MY_LAYOUT, error) {
***@***.***()</p> --- nullpointer if obj is null
}
My requirement is that if there are error objects in the parameters, i do
not want to render the page template content as the required parametes
could be null, and let the layout template display the error messages.
The layout template example:
@Args(MyError err, RockerContent content)
if (err.hasErrors()) {
***@***.***(obj)</ul>
} else {
@content
}
The problem here is, the RockerContent of the page must be rendered first,
before sending the content to the layout template.
I could use @if <https://github.com/if> in the page template to check for
the existence of the error objects, but this means lots of duplicated @if
<https://github.com/if> in all pages that reuse this template layout.
Furthermore all extrajs and extracss RockerBody would need to have this
conditioning too.
Workaround on the page template example:
@Args(MyObj obj, MyError error)
@Rocker.template(MY_LAYOUT, error) {
if (!err.hasErrors()) { // works fine, but code duplications in many other page templates
***@***.***()</p> --- nullpointer if obj is null
}
}
Is there any way i could render a section (RockerBody-s and
RockerContent-s) conditionally from the layout template without having to
specify @if <https://github.com/if> manually in the page templates ?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#134?email_source=notifications&email_token=AAEPAAVIQYI73D4IMTBDM3TRE5QE5A5CNFSM4K4U6VG2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IQV6YFA>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEPAAR5MPR2U7RUEUZ7HM3RE5QE5ANCNFSM4K4U6VGQ>
.
|
I deeply apologize for the confusion. Allow me to make it simpler this time. The steps of executions:
The key issue is at (2) because it has to render the content before passing it to MyLayout.rocker.html. The rendering fails because the parameters needed to render the MyPage content are of null values as returned by the backend. The expectation is that upon this validationError situation, the MyLayout displays the error messages, without even rendering the MyPage.html content. How do i do this without having to do null or validationResult checking in MyPage.rocker.html and delegate the checking and displaying of error messages to MyLayout.rocker.html ? Thank you .. |
I am having a common situation where a page template is using a common layout template for generating a html page.
The page template example:
My requirement is that if there are error objects in the parameters, i do not want to render the page template body as the required parametes could be null, and let the layout template display the error messages.
The layout template example:
The problem here is, the RockerBody of the page must be rendered first, before sending the rendered content to the layout template.
I could use @if in the page template to check for the existence of the error objects, but this means lots of duplicated @if in all pages that reuse this template layout.
Furthermore all extrajs and extracss RockerContent-s would need to have this conditioning too.
Workaround on the page template example:
Is there any way i could render a section (RockerBody or RockerContent) conditionally from the layout template without having to specify @if manually in the page templates ?
The text was updated successfully, but these errors were encountered: