M.Zharkikh's personal site logo
Mail to site
Print version
News (RSS)
Smereka / Smeretags / Conditional smeretags

Smereka

Smeretags

Conditional smeretags

Conditional smeretags similar to conditional operators in programming languages: they check certain conditions and depending on the results generated (or not generate) some code.

CondAttr

Module: smeretags/substfields.php (available by default)

Options: AttrName SmerekaValue.

Purpose: returns the value of required parameter SmerekaValue, if contextual node has an attribute named AttrName (this parameter is also required). If the node has no such attribute, it returns an empty string.

If the parameter have ! (exclamation point) before the name, the action inverts: SmerekaValue value returned if node has no such attribute, empty string is returned when the node has an attribute named AttrName.

Example Call: <Smereka1 Func="CondAttr" AttrName="Author">: <Smereka Func="GetNodeAttr" AttrName="Author" /><Smereka1>

Example result:

Author: W.Shakespeare [assuming that the node has the attribute Author]

[empty string assuming that the node has no attribute Author]

If we had only limited code Author: <Smereka Func="GetNodeAttr" AttrName="Author" />, label Author: show a like always, even when the author is not given. With the conditional smeretag we can hide it when not needed.

Example call: Author: <Smereka1 Func="CondAttr" AttrName="Author"><Smereka Func="GetNodeAttr" AttrName="Author" /><Smereka1><Smereka1 Func="CondAttr" AttrName="!Author">undefined<Smereka1>

Example result:

Author: W.Shakespeare [assuming that the node has the attribute Author]

Author: undefined [assuming that the node has no attribute Author]

It used two conditional smeretags, one of which is performed in the presence attribute Author, and second with his absence.

AttrsEq

Module: smeretags/cond.php

Options: AttrName1 AttrName2 SmerekaValue.

Purpose: returns the value of required parameter SmerekaValue, if contextual node has attributes with the names AttrName1 and AttrName2 (these parameters also are required) and value these attributes match. If these conditions are not met, an empty string returned.

AttrsNotEq

Module: smeretags/cond.php

Options: AttrName1 AttrName2 SmerekaValue.

Purpose: returns the value of required parameter SmerekaValue, if contextual node has attributes with the names AttrName1 and AttrName2 (these parameters also are required) and value these attributes do not match. Empty string is returned if one or both attributes are missing, or if their values match.

The practical problem: there is a collection of poems (all of which have the same attribute ProjectId). Inside the collection is a cycle of poems with their child nodes. We must bring a navigation unit, which would provide navigation between verses in cycle (if the poem belong to cycle).

Example call:

<Smereka11 Module="smeretags/cond.php" Func="AttrsNotEq"
AttrName1="parent" AttrName2="ProjectId">
<h3><Smereka Func="GetDocTitle"
NodeId="{Smereka Func="GetNodeAttr" AttrName="parent" /}"/>
</h3>
<p class="BodyCenter">
 <Smereka Func="SmerefRelative"
rel="prevsibl">Previous rhyme</Smereka> |
 <Smereka Func="SmerefRelative"
rel="parent">List of rhymes</Smereka> |
 <Smereka Func="SmerefRelative"
rel="nextsibl">Next rhyme</Smereka>
</p>
</Smereka11>

How does this work: zest is conditional smeretag that checks the discrepancy between attributes parent and ProjectId. If these attributes match this node directly subordinate to the project root node (ie verse is not a part of the cycle). If these attributes do not match we assume the parent indicates the cycle, get its name and output block navigation. To watch this system in operation, you can see a Lesja Ukrainka's collection "On the wings of songs".

Previous section | Table of content | Next section

Please this page? Help us to develop this site!

1978 2018 N.I.Zharkikh

Reprinting of articles from site are encouraged while
reference (hyperlink) to my site is provided

Site powered by

Load count : 1257

Modified : 8.08.2017

If you look up the type error
on this page, please select it
by mouse and press Ctrl+Enter.