Skip to content

Instantly share code, notes, and snippets.

@ydn
Created March 9, 2010 19:44
Show Gist options
  • Save ydn/327012 to your computer and use it in GitHub Desktop.
Save ydn/327012 to your computer and use it in GitHub Desktop.
Tabbed navigation for YAP small view
Motivation:
- Suppose you are building an application for the Yahoo! Application Platform (YAP), and want a tabbed navigation in the small view. This code provides a simplified example of how to construct such navigation.
Flow:
1) The small view will first load the default content (see below), which will callback to this code to fetch the output defined in the else clause of this code.
2) That content will then use a yml:include tag to call back to itself with the parameter "item=1".
3) The script will then execute the if statement and return the default body content for the app.
Usage:
1) Copy/paste this code into the index file at the root of your app. For example, if the base url for your app is http://example.com/index.php, put this code in index.php. Be sure to remove/comment-out any code already in index.php that may interfere.
2) Put the following code in the default small view code box in the YAP dashboard: <yml:include>loading...</yml:include>. Note that because the "params" attribute is omitted from the yml:include tag, the tag will call back to the app's base url by default.
3) Preview your app's small view in the YAP dashboard. You should see "loading...", followed by the appearance of your "tabs" ("item 1 | item 2 | item 3") above the text "loading ...", followed by the replacement of the loading text with "this is item 1 content"
Note:
- Because this is just sample code, security and validation measures have been omitted to reduce complexity. Please add these before using this code in a live app.
License:
- Software License Agreement (BSD License) Copyright (c) 2009, Yahoo! Inc. All rights reserved.
- Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<?php // Tabbed navigation for YAP small view
// See usage and license details in http://gist.github.com/327012/#file_readme.txt
?>
<? if('1' == $_GET['item']): ?>
this is item 1 content
<? elseif('2' == $_GET['item']): ?>
this is item 2 content
<? elseif('3' == $_GET['item']): ?>
this is item 3 content
<? else: ?>
<div><!-- nav -->
<yml:a params="?item=1" insert="content">item 1</yml:a> |
<yml:a params="?item=2" insert="content">item 2</yml:a> |
<yml:a params="?item=3" insert="content">item 3</yml:a>
</div>
<div id="content"><!-- body -->
<yml:include params="?item=1">loading...</yml:include>
</div>
<? endif ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment