Skip to content

Commit

Permalink
If tests and documentation expanded
Browse files Browse the repository at this point in the history
  • Loading branch information
zozlak committed Aug 27, 2024
1 parent 83ee837 commit 8c78c09
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
18 changes: 17 additions & 1 deletion doc/TemplateMetadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ display only authors having a homepage:
<a>
```

If the `foreach` is combined with the `if` in a single tag, the `if` statement is evaluated in the `foreach`
"source" resource context. What you typically want is to evalute the `if` in the context of resources
the `foreach` iterates trough. To achieve that, use a following syntax:

```xml
<doesnotmatter foreach="/acdh:hasAuthor" remove="remove">
<a if="some condition - see the if docs">
<uri val="/^acdh:hasHomepage"/>
<title val="/^acdh:hasHomepage/acdh:hasAuthor"/>
<homepage val="CURNODE"/>
</a>
</doesnotmatter>
```

### if

Skips evaluation of child tags if a given condition is not fulfilled.
Expand All @@ -352,6 +366,8 @@ E.g.
* `if="any(rdf:hasRawBinarySize) OR none(acdh:hasLicenseSummary)"` if there is
any `acdh:hasRowBinarySize` RDF property value or no `acdh:hasLicenseSummary` property

Please note that if you combine `if` and `foreach` in a one tag, then the `if` is evaluated in the
original resource context. See the `foreach` description for more detailed disccussion.

### XML entities

Expand All @@ -375,4 +391,4 @@ Using XML entities it is possible to include subtemplates, e.g.
<title val="acdh:hasTitle"/>
<memberOf val="acdh:isMemberOf/acdh:hasTitle"/>
</agent>
```
```
2 changes: 2 additions & 0 deletions tests/TemplateMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public function testIf(): void {
<n>3</n>
<o><oo>ch1</oo><oo>ch2</oo></o>
<pp>ch1</pp><pp>ch2</pp>
<q>single's</q>
<r>single's</r>
</root>
OUT;
$this->assertEquals($this->std($expected), $xml);
Expand Down
1 change: 1 addition & 0 deletions tests/data/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ xmlErrors: true
rdfNamespaces:
base: https://
skos: http://www.w3.org/2004/02/skos/core#
local: http://127.0.0.1/api/
valueMaps:
tag:
tag1: TAG ONE
Expand Down
2 changes: 2 additions & 0 deletions tests/data/if.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@
<pp val="=ch1"/>
<pp val="=ch2"/>
</p>
<q if="any(base:author == 'http://127.0.0.1/api/345')" val="/base:single"></q>
<r if="any(base:author == local:346)" val="/base:single"></r>
</root>

0 comments on commit 8c78c09

Please sign in to comment.