Closed scypio closed 5 years ago
Features implemented so far:
just add knotx-data-fallback="BLANK"
to your snippet:
<knotx-snippet data-knotx-knots="databridge,handlebars"
data-knotx-databridge-name="unstable-service"
data-knotx-fallback="BLANK">
{{#if _result}}<h2>{{_result.count}}</h2>{{/if}}
</knotx-snippet>
create a fallback snippet with data-knotx-fallback-id
attribute and point to it in your snippet:
<knotx-snippet data-knotx-knots="databridge,handlebars"
data-knotx-databridge-name="unstable-service"
data-knotx-fallback="CUSTOM">
{{#if _result}}<h2>{{_result.count}}</h2>{{/if}}
</knotx-snippet>
<knotx:fallback data-knotx-fallback-id="CUSTOM">
<p class="error">error</p>
</knotx:fallback>
to apply BLANK fallback to all snippets by default configure defaultFallback
attribute within snippetOptions
- apply these to both Splitter and FragmentAssembler.
snippetOptions {
tagName = knotx-snippet
paramsPrefix = data-knotx-
defaultFallback = BLANK
}
to apply custom markup fallback to all snippets by default:
defaultFallback
attribute within snippetOptions
fallbacks
property within snippetOptions
snippetOptions {
tagName = knotx-snippet
paramsPrefix = data-knotx-
defaultFallback = CUSTOM_GLOBAL
fallbacks = [
{
id = CUSTOM_GLOBAL
markup = "<knotx:fallback data-knotx-fallback-id='CUSTOM_GLOBAL'><p class="error">error</p></knotx:fallback>"
}
]
}
you can deliver your own class that will be fired by the assembler if given fragment fails
import io.knotx.dataobjects.Fragment;
import io.knotx.dataobjects.KnotContext;
import io.knotx.fallback.FallbackStrategy;
public class MyFallbackStrategy implements FallbackStrategy {
@Override public String getId() { return "CUSTOM_STRATEGY"; }
@Override public String applyFallback(Fragment failed, Fragment fallback, KnotContext knotContext) { return "
markup
"; } }- make sure that `ServiceLoader` can discover this class - add its fully qualified name to `/META-INF/services/io.knotx.fallback.FallbackStrategy` file.
- create a custom fallback snippet with linked strategy Id
<knotx-snippet data-knotx-knots="databridge,handlebars" data-knotx-databridge-name="unstable-service" data-knotx-fallback="CUSTOM"> {{#if _result}}
error
I am wondering if this tag data-knotx-fallback="BLANK"
is really required. We can assume that if there is no data-knotx-fallback-id
tag defined, then the default fallback mechanism should handle the snippet.
According to 5: We agreed that a fallback strategy should be configured as a chain, something like:
"fallbackStrategies": [
{ "name": "CUSTOM", conf":"{next:"DEFAULT"" }},
{ "name": "DEFAULT", "conf":"EMPTY" }
]
In that way our fallback strategy implementation should pass the flow to the next fallback. I thought about something similar to io.knotx.server.handler.knot.KnotEngineRoutingHandlerFactory.KnotxEngineHandler#handleRoute.
Can we move this comment to the SnippetFallback.md
file - we could work on documentation in the same PR. We plan to move documentation from wiki to *.md files so it can be good option.
Please see my https://github.com/Cognifide/knotx/issues/466#issuecomment-435311790. I described there few implementation details that will make this solution easier to extend in the future.
IMPLEMENTATION IN PROGRESS
Description
Implementation of #466
Motivation and Context
Screenshots (if appropriate)
Upgrade notes (if appropriate)
Types of changes
Checklist:
I hereby agree to the terms of the Knot.x Contributor License Agreement.