Open line-o opened 1 year ago
@line-o please rebase
@duncdrum done! Thanks for merging the other PRs
@line-o p.s. As long as this involves breaking changes, I'm not sure if you want to resurrect a previously reverted breaking change from @wolfgangmm involving the lib:parse-params()
function? See the details here: https://github.com/eXist-db/templating/issues/8.
You are right @joewiz ! We should definitely include those in the next major version.
Also food for discussion is where to put which functions. As it is now possible to use only functions in the templates namespace, which functionality does it have to provide to be useful on its own?
templates:render
, templates:apply
)templates:for-each
)templates:include
)
<a data-template="templates:include" data-template-path="model(page-template)" />
<a data-template="templates:text" data-template-text="model(link-text)" />
@joewiz There is no need to reincorporate the reverted changes from #8 as the delimiters can no longer be set in templates but are now set once in the configuration.
If, however, this is not acceptable then we would have to look into this once more.
Hello, sorry to be a bit late to the party!
I had some suggestions which I've previously raised with @joewiz for improving some aspects of the templating system; I've added them here as feature request #20 : is there any mileage in considering a similar solution as part of this next version?
Looking at the code, the implementation still looks fairly straightforward, with the suggested changes to templates:process
now occurring in templates:process-element
instead.
I wonder if it would make sense to have parse-params
enabled by default, which means it would be active unless you stop it for some part of the tree, e.g. with disable-parse
. This would align with other templating engines (e.g. in Nunjucks you use raw
to stop substitution).
I appreciate your feedback, honestly. Good stuff here @duncdrum @wolfgangmm
parse-params
(@wolfgangmm): I agree that parsing placeholders should be transparent to the user of the library. Can you imagine a case where you would not want placeholders to be replaced? Would you be open for a discussion on how to implement this? Use expand-blocks
instead of process-children
? @line-o i can help with the docs
@wolfgangmm your proposal is now part of this PR
I have an additional question regarding the handling of the now obsolete declaration of data-template="lib:parse-params"
.
Should templates that are rendered with this new version of templating that still include it throw or the declaration just be ignored?
Is it worth it keeping this extra check in the library or even harmful as those declarations stay in there? I am leaning towards throwing an error rather than ignoring the declaration.
+1 for throwing an error, explicit design >> black box design
@yamahito I decided to make a cut and implemented your original proposal with an additional error-check when both data-template-use-when
and data-template-use-unless
are set on a single element.
The feedback from the community
data-template="templates:parse-params"
obsoleteNOTE: #22 is out of scope as it can be implement later as a configuration option
Embrace the top-down approach by allowing dynamic includes
with main page template, which is passed to
templates:render
and a model, (the second parameter to
templates:render
)It is feasible to create quite flexible template structures that are easier to reason about. You do not need many, maybe no custom template function at all.
Don't worry
templates:surround
is still... around.BREAKING CHANGES
templates:parse-params
(could be renamed totemplates:substitute
) must be set as configuration options now. This also means there is no way to change them somewhere in between.$templates:CONFIG_FILTER_ATTRIBUTES : false()
in the options.lib:resolve-apps
is now part of a new module calledtmpl-apps
and the function was renamed totmpl-apps:by-abbrev
. It will put all resolved application paths into a map in the model under theapps
key. Retrieval is done by<p id="test1">${apps?templating-test}</p>
.FEATURES
Function resolution
You can pass in
xs:QName(?)
as CONFIG_QNAME_RESOLVER instead of passing in a function that callsfn:function-lookup
CONFIG_FN_RESOLVER. Due to a an issue in eXist-db's XQuery implementation (see https://github.com/eXist-db/exist/issues/4614 ) this can only resolve functions from imported modules at the time of writing. The old approach can be used as before. If you pass in none of the above the default resolver will still allow you to use all basic template functions intemplates
namespace.Parameter resolution
The configuration option for parameter resolution can now contain a sequence of functions
(function(xs:string) as item()*)*
where it had to be a single function before. This allows for greater control over where parameter values are read from. Defaults toError reporting
when a template function cannot be resolved then the node is serialised in the error message to make it easier to find where the issue has occurred
New entry point
templates:render
is a shorthand totemplates:apply
where the lookup is passed as part of the configMax arity
With
$templates:CONFIG_MAX_ARITY
you can now specify the maximum arity of template functions. Defaults to 8 was 20.Placeholder replacement
Before you had to declare
data-template="templates:parse-params"
(that wasdata-template="lib:parse-params"
respectively in 1.1.0) to have placeholders in attributes and text nodes replaced. This is no longer necessary and placeholders will always be replaced using the provided resolvers or the model.Changes
templates:resolve-key($model, $key)
will call the configured parameter resolvers internallyAs the tests show this version does raise the minimum required processor version to eXist-db v5.4.1 because of NPEs in v5.2.0.