├── .gitignore ├── README.md ├── CONTRIBUTING.md ├── CODE_OF_CONDUCT.md ├── CHANGELOG.md ├── LICENSE └── SPECIFICATION.md /.gitignore: -------------------------------------------------------------------------------- 1 | atlassian-ide-plugin.xml 2 | target 3 | .idea 4 | .classpath 5 | .project 6 | .settings 7 | .checkstyle 8 | *.iml 9 | *.ipr 10 | *.iws 11 | *.class 12 | bin 13 | .vlt 14 | .vlt-sync-config.properties 15 | .vlt-sync.log 16 | .DS_Store 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | HTML Template Language Specification 2 | ==== 3 | The [HTML Template Language](https://experienceleague.adobe.com/docs/experience-manager-htl/content/overview.html "HTL Guide") (HTL), formerly known as Sightly, has been introduced with [Adobe Experience Manager](http://www.adobe.com/solutions/web-experience-management.html) 6.0 and takes the place of JSP (JavaServer Pages) as the preferred and recommended server-side template system for HTML. 4 | 5 | This is the [HTL Specification](https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md) that defines the syntax and the behavior of the language. 6 | 7 | A Java-based reference implementation has been [donated to the Apache Sling project](https://issues.apache.org/jira/browse/SLING-3959) and can be checked out from https://github.com/apache/sling/tree/trunk/bundles/scripting/sightly. 8 | 9 | The [Technology Compatibility Kit](https://github.com/adobe/htl-tck) can be run on implementations to check their compliance with the specification. 10 | 11 | An implementation of [version 1.4](https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md) of the language specification is available in AEM 6.3 SP3 and AEM 6.4 SP1. 12 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thanks for choosing to contribute! 4 | 5 | The following are a set of guidelines to follow when contributing to this project. 6 | 7 | ## Code Of Conduct 8 | 9 | This project adheres to the Adobe [code of conduct](CODE_OF_CONDUCT.md). By participating, 10 | you are expected to uphold this code. Please report unacceptable behavior to 11 | [Grp-opensourceoffice@adobe.com](mailto:Grp-opensourceoffice@adobe.com). 12 | 13 | ## Have A Question? 14 | 15 | Start by filing an issue. The existing committers on this project work to reach 16 | consensus around project direction and issue solutions within issue threads 17 | (when appropriate). 18 | 19 | ## Contributor License Agreement 20 | 21 | All third-party contributions to this project must be accompanied by a signed contributor 22 | license agreement. This gives Adobe permission to redistribute your contributions 23 | as part of the project. [Sign our CLA](http://opensource.adobe.com/cla.html). You 24 | only need to submit an Adobe CLA one time, so if you have submitted one previously, 25 | you are good to go! 26 | 27 | ## Code Reviews 28 | 29 | All submissions should come in the form of pull requests and need to be reviewed 30 | by project committers. Read [GitHub's pull request documentation](https://help.github.com/articles/about-pull-requests/) 31 | for more information on sending pull requests. 32 | 33 | Lastly, please follow the [pull request template](PULL_REQUEST_TEMPLATE.md) when 34 | submitting a pull request! 35 | 36 | ## From Contributor To Committer 37 | 38 | We love contributions from our community! If you'd like to go a step beyond contributor 39 | and become a committer with full write access and a say in the project, you must 40 | be invited to the project. The existing committers employ an internal nomination 41 | process that must reach lazy consensus (silence is approval) before invitations 42 | are issued. If you feel you are qualified and want to get more deeply involved, 43 | feel free to reach out to existing committers to have a conversation about that. 44 | 45 | ## Security Issues 46 | 47 | Security issues shouldn't be reported on this issue tracker. Instead, [file an issue to our security experts](https://helpx.adobe.com/security/alertus.html) 48 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Adobe Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at Grp-opensourceoffice@adobe.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | HTML Template Language Specification [1.4.1](https://github.com/adobe/htl-spec/tree/1.4.1) - TBD 2 | ==== 3 | Version 1.4.1 is a micro release that clarifies some of the wording from version 1.4 or provides more guidance for implementations. 4 | 5 | For a full list of issues addressed by this release please check [8]. 6 | 7 | [8] - https://github.com/adobe/htl-spec/milestone/4?closed=1 8 | 9 | HTML Template Language Specification [1.4](https://github.com/adobe/htl-spec/tree/1.4) - June 18th, 2018 10 | ==== 11 | Version 1.4 brings the following enhancements: 12 | * `data-sly-list` and `data-sly-repeat` iteration control (#55) [0][1] 13 | * the introduction of the `in` relational operator (#56) [2] 14 | * support for negative Number literals (#44) [3] 15 | * attribute identifier for the `data-sly-unwrap` block statement (#52) [4] 16 | * an extended list of attributes for which the `uri` display context is applied automatically (#62) [5] 17 | * a new block statement - `data-sly-set` [6] 18 | 19 | For a full list of issues addressed by this release please check [7]. 20 | 21 | [0] - https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md#226-list 22 | [1] - https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md#227-repeat 23 | [2] - https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md#1143-relational-operators 24 | [3] - https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md#111-grammar 25 | [4] - https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md#2211-unwrap 26 | [5] - https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md#113-context-sensitive 27 | [6] - https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md#2212-set 28 | [7] - https://github.com/adobe/htl-spec/milestone/3?closed=1 29 | 30 | HTML Template Language Specification [1.3.1](https://github.com/adobe/htl-spec/tree/1.3.1) - August 1st, 2017 31 | ==== 32 | Enhancements: 33 | * corrected examples from the [URI manipulation](https://github.com/adobe/htl-spec/blob/1.3.1/SPECIFICATION.md#125-uri-manipulation) section 34 | * added paragraph about the style and the event attributes for the `data-sly-attribute` block element 35 | 36 | HTML Template Language Specification [1.3](https://github.com/adobe/htl-spec/tree/1.3) - March 16th, 2017 37 | ==== 38 | New features: 39 | - the [`format`](https://github.com/adobe/htl-spec/blob/1.3/SPECIFICATION.md#122-format) option has been extended to allow formatting `strings`, `dates` and `numbers` 40 | 41 | 42 | HTML Template Language Specification [1.2](https://github.com/adobe/htl-spec/tree/1.2) - March 30th, 2016 43 | ==== 44 | 45 | New Features: 46 | * allow Java enums to be used in [comparisons](https://github.com/adobe/htl-spec/blob/1.2/SPECIFICATION.md#1142-comparison-operators) 47 | 48 | Enhancements: 49 | * documented the `data-sly-include` `file` option, which was present in the [TCK](https://github.com/adobe/htl-tck/blob/io.sightly.tck-1.0.0/src/main/resources/testfiles/scripts/blockstatements/include/include.html#L27) + reference implementation since 1.0 50 | 51 | HTML Template Language Specification [1.1](https://github.com/adobe/htl-spec/tree/1.1) - February 16th, 2015 52 | ==== 53 | 54 | New Features: 55 | * [`styleComment`](https://github.com/adobe/htl-spec/blob/1.1/SPECIFICATION.md#121-display-context) display context 56 | * [URI manipulation](https://github.com/adobe/htl-spec/blob/1.1/SPECIFICATION.md#125-uri-manipulation) options 57 | * [`data-sly-repeat`](https://github.com/adobe/htl-spec/blob/1.1/SPECIFICATION.md#227-repeat) block element 58 | * special HTML tags - [``](https://github.com/adobe/htl-spec/blob/1.1/SPECIFICATION.md#31-sly) 59 | 60 | Enhancements: 61 | * the [`join`](https://github.com/adobe/htl-spec/blob/1.1/SPECIFICATION.md#124-array-join) option can also be used with a simple string, outputting just the string in this case 62 | * for [`data-sly-list`](https://github.com/adobe/htl-spec/blob/1.1/SPECIFICATION.md#226-list) (and also for [`data-sly-repeat`](https://github.com/adobe/htl-spec/blob/1.1/SPECIFICATION.md#227-repeat)) the element will be shown only if the attribute's value provides a non-empty collection, a string or a number 63 | * no need to strictly define [reserved options](https://github.com/adobe/htl-spec/blob/1.0/SPECIFICATION.md#13-reserved-options) like in 1.0 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /SPECIFICATION.md: -------------------------------------------------------------------------------- 1 | HTML Template Language Specification 2 | ==== 3 | 4 | **Version:** 1.4 5 | **Authors:** Radu Cotescu, Marius Dănilă, Peeter Piegaze, Senol Tas, Gabriel Walt, Honwai Wong 6 | **License:** [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt) 7 | **Status:** Final release 8 | **Release:** 18 June 2018 9 | 10 | #### Contents 11 | 1. [Expression language, syntax and semantics](#1-expression-language-syntax-and-semantics) 12 | 1. [Syntax](#11-syntax) 13 | 1. [Grammar](#111-grammar) 14 | 2. [Expressions](#112-expressions) 15 | 3. [Context-Sensitive](#113-context-sensitive) 16 | 4. [Operators](#114-operators) 17 | 1. [Logical Operators](#1141-logical-operators) 18 | 2. [Comparison Operators](#1142-comparison-operators) 19 | 3. [Relational Operators](#1143-relational-operators) 20 | 5. [Casting](#115-casting) 21 | 1. [Boolean](#1151-boolean) 22 | 2. [String](#1152-string) 23 | 6. [Options](#116-options) 24 | 7. [Parametric Expressions](#117-parametric-expressions) 25 | 8. [Whitespace](#118-whitespace) 26 | 9. [Comments](#119-comments) 27 | 2. [Available Expression Options](#12-available-expression-options) 28 | 1. [Display Context](#121-display-context) 29 | 2. [Format](#122-format) 30 | 1. [Strings](#1221-strings) 31 | 2. [Dates](#1222-dates) 32 | 3. [Numbers](#1223-numbers) 33 | 3. [i18n](#123-i18n) 34 | 4. [Array Join](#124-array-join) 35 | 5. [URI Manipulation](#125-uri-manipulation) 36 | 2. [Block Statements](#2-block-statements) 37 | 1. [Syntax](#21-syntax) 38 | 1. [Identifiers](#211-identifiers) 39 | 2. [Available Block Statements](#22-available-block-statements) 40 | 1. [Use](#221-use) 41 | 2. [Text](#222-text) 42 | 3. [Attribute](#223-attribute) 43 | 1. [Detailed Examples](#2231-detailed-examples) 44 | 4. [Element](#224-element) 45 | 5. [Test](#225-test) 46 | 6. [List](#226-list) 47 | 7. [Repeat](#227-repeat) 48 | 8. [Include](#228-include) 49 | 9. [Resource](#229-resource) 50 | 10. [Template & Call](#2210-template--call) 51 | 1. [Template](#22101-template) 52 | 2. [Call](#22102-call) 53 | 3. [Examples](#22103-examples) 54 | 11. [Unwrap](#2211-unwrap) 55 | 12. [Set](#2212-set) 56 | 3. [Block Statements Priority](#23-block-statements-priority) 57 | 3. [Special HTML tags](#3-special-html-tags) 58 | 1. [<sly>](#31-sly) 59 | 4. [Use-API](#4-use-api) 60 | 1. [Java Use-API](#41-java-use-api) 61 | 2. [JavaScript Use-API](#42-javascript-use-api) 62 | 63 | ## 1. Expression language, syntax and semantics 64 | 65 | ### 1.1. Syntax 66 | 67 | #### 1.1.1. Grammar 68 | The grammar of the HTL Expression Language is pretty simple and can be summarised to the following definitions: 69 | 70 | expression = '${' , [exprNode] , [ , '@' , optionList] , '}' ; 71 | 72 | optionList = option {',' , option} ; 73 | 74 | option = id [ , '=' , optionValues] ; 75 | 76 | optionValues = exprNode 77 | | '[' , valueList , ']' ; 78 | 79 | valueList = exprNode {',' exprNode} ; 80 | 81 | exprNode = orBinaryOp , '?' , orBinaryOp , ws , ':' , ws , orBinaryOp 82 | | orBinaryOp ; 83 | 84 | orBinaryOp = andBinaryOp {, '||', andBinaryOp}; 85 | 86 | andBinaryOp = inBinaryOp {, '&&', inBinaryOp}; 87 | 88 | inBinaryOp = comparisonOp [, 'in', comparisonOp]; 89 | 90 | comparisonOp = factor [, comparisonOperator, factor]; 91 | 92 | comparisonOperator = '<' 93 | | '<=' 94 | | '==' 95 | | '>=' 96 | | '>' 97 | | '!=' ; 98 | 99 | factor = term 100 | | '!' , term ; 101 | 102 | term = propertyAccess 103 | | '(' , exprNode , ')' 104 | | '[', valueList, ']' ; 105 | 106 | /* Note the 'comma rule' means zero or more whitespace characters. Used to indicate optional whitespace around terminals above */ 107 | , = {ws} ; 108 | 109 | ws = ' ' 110 | | '\t' 111 | | '\r' 112 | | '\n' 113 | | '\u000B' 114 | | '\u00A0'; 115 | 116 | /* Note that unlike terminals above, the field access character '.' cannot have optional whitespace around it */ 117 | propertyAccess = atom {'.' id} 118 | | atom {'[' , exprNode , ']'}; 119 | 120 | atom = string 121 | | id 122 | | int 123 | | float 124 | | bool ; 125 | 126 | bool = 'true' 127 | | 'false' ; 128 | 129 | id = ('a'..'z'|'A'..'Z'|'_') {'a'..'z'|'A'..'Z'|'0'..'9'|'_'|':'} ; 130 | 131 | int = ['-']('1'..'9'){'0'..'9'} 132 | | '0' ; 133 | 134 | float = ['-']('1'..'9'){'0'..'9'} '.' {'0'..'9'} [exponent] 135 | | ['-']'0.' ('0'..'9') {'0'..'9'} [exponent] 136 | | ['-']('1'..'9'){'0'..'9'} exponent ; 137 | 138 | /* An HTL comment can contain any character sequence other than '*/-->' */ 139 | comment = '')} '*/-->' ; 140 | 141 | /* A string can be delimited by either double or single quotes. Within these delimiters it may contain either escape sequences or any characters other than backslash and whichever quote was used for delimiting. */ 142 | string = '"' {escSeq | -('\\' | '"')} '"' 143 | | '\'' {escSeq | -('\\'|'\'')} '\'' ; 144 | 145 | exponent = ('e'|'E') ['+'|'-'] ('0'..'9'){'0'..'9'} ; 146 | 147 | escSeq = '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') 148 | | unicodeEsc; 149 | 150 | unicodeEsc = '\\' 'u' hexDigit hexDigit hexDigit hexDigit ; 151 | 152 | hexDigit = ('0'..'9'|'a'..'f'|'A'..'F') ; 153 | 154 | The above grammar is adapted from the [source ANTLR files](https://github.com/apache/sling-org-apache-sling-scripting-sightly-compiler/tree/master/src/main/antlr4/org/apache/sling/scripting/sightly/impl/parser/expr/generated). It uses the following conventions: 155 | 156 | foo Alphabetic words and comma (',') are rule names. 157 | /**/ Slash-star and star-slash delimit comments. 158 | Whitespace within a rule production indicates direct concatenation. 159 | = Equals sign indicates the rule production. 160 | ; Semicolon indicates end of production. 161 | ' ' Single quotes delimit terminals. 162 | | Pipe indicates OR. 163 | [] Square brackets indicate an option (zero or one times). 164 | {} Curly brackets indicate repetition (zero or more times). 165 | - Minus sign indicates 'any character or character sequence other than the following'. 166 | .. Ellipses indicates a range between two single-character terminals, by collation order. 167 | 168 | [Like in JavaScript](http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4), strings quotes can be escaped by prefixing a backslash to the quote (`\'`) or double-quote (`\"`). 169 | 170 | Single character escape sequences: `\t \b \n \r \f \' \" \\` 171 | 172 | Unicode escape sequences: `\u` followed by 4 hexadecimal digits (e.g.: `\u0022` for `"`, `\u0027` for `'`, `\u003c` for `<`, or `\u003e` for `>`) 173 | 174 | Like in JSP (see section "1.2.2 Literal-expression" from the [JSP 2.1 Expression Language Specification](http://download.oracle.com/otn-pub/jcp/jsp-2.1-fr-spec-oth-JSpec/jsp-2_1-fr-spec-el.pdf)), to escape an expression (the `${`), it can be prefixed it with a backslash (`\${`). 175 | 176 | #### 1.1.2. Expressions 177 | Here are some examples of HTL expressions: 178 | 179 | ```html 180 | 181 | ${myVar} 182 | 183 | 184 | ${myObject.key} 185 | ${myObject['key']} 186 | ${myObject[keyVar]} 187 | 188 | 189 | ${myArray[1]} 190 | ${myArray[indexVar]} 191 | 192 | 193 | ${true} 194 | ${42} 195 | ${'string'} 196 | ${"string"} 197 | ${[1, 2, 3, true, 'string']} 198 | ``` 199 | 200 | #### 1.1.3. Context-Sensitive 201 | Expressions can be used in following contexts for outputting identifiers into the markup with automatic context-aware XSS protection. 202 | 203 | ```html 204 | Some text ${myText} 205 | 206 | 207 | ``` 208 | 209 | HTL expressions used to output values for the following HTML attributes that provide URIs or URLs will automatically be processed with the 210 | `uri` [display context](#121-display-context), unless an explicit `context` is provided: 211 | * `action` (`
`) 212 | * `cite` (`
`, ``, ``, `` tags) 213 | * `data` (``) 214 | * `formaction` (`