forked from overhacked/Cascade-Server-Velocity-Examples
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example of embedding JavaScript in Velocity format
- Loading branch information
1 parent
6bbfd91
commit ec54719
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#* | ||
This format generates a drop-menu which, upon selection, will jump to a pre-defined Cascade page aggregating | ||
articles based on the selected expert area. The menu itself will be generated by a Content Type index block, referencing | ||
all pages of type 'ArticlesByExpertArea.' Each of these page will have a dynamic-metadata value named 'expert-area' specifying | ||
the exact expert area to aggregate. It is this value which will be displayed in the "Browse by Expert Area" drop-menu generated | ||
in this format. | ||
*# | ||
|
||
## use a macro to set the selected expert area | ||
#macro ( setExpertArea $asset ) | ||
|
||
## reset to baseline | ||
#set ( $expertArea = "NONE" ) | ||
## use $_XPathTool to extract the specified expert-area value from the given $asset | ||
#set ( $expertArea = $_XPathTool.selectSingleNode($asset,"dynamic-metadata[name = 'expert-area']/value").text ) | ||
|
||
#end | ||
|
||
## baseline | ||
#set ( $expertArea = "NONE" ) | ||
|
||
## get a list of all "Expert Area" index pages (i.e. all pages of Content Type 'ArticlesByExpertArea') | ||
#set ( $expertIndexes = $_XPathTool.selectNodes(${contentRoot},"//system-page[dynamic-metadata[name = 'expert-area']]") ) | ||
|
||
## sort the results alphabetically by 'expert-area' | ||
$_SortTool.addSortCriterion("dynamic-metadata[name = 'expert-area']/value", "", "text", "ascending", "") | ||
$_SortTool.sort($expertIndexes) | ||
|
||
## use JavaScript function to jump to specified aggregate page | ||
<script language="JavaScript"> | ||
|
||
function browseExpertise(menu) | ||
{ | ||
var gotoURL = menu.options[menu.selectedIndex].value; | ||
if (gotoURL != "NONE") | ||
{ | ||
top.location.href = gotoURL; | ||
} | ||
} | ||
|
||
</script> | ||
|
||
## output menu in an <h4> | ||
<h4>Expert Area: | ||
|
||
<select onChange="browseExpertise(this);"> | ||
<option value="NONE" selected="true">Browse by Expert Area...</option> | ||
|
||
## loop through all 'ArticleByExpertArea' pages & output their respective 'expert-areas' in the "Browse by..." menu | ||
#foreach ( $expertIndex in $expertIndexes ) | ||
#set ( $url = $expertIndex.getChild("path").text ) | ||
## execute the macro to set the $expertArea variable | ||
#setExpertArea ( $expertIndex ) | ||
<option value="[system-asset]${url}[/system-asset]"><a href="${url}" target="_parent" title="${expertArea}">${expertArea}</a></option> | ||
#end | ||
|
||
</select> | ||
</h4> |