Search these areas:
Help
Support Forums
Product Info



-Introduction
-DataWeb: What's New
-Creating an Application
-The DataWeb Designer
-Application Management
-Data Tables
-Data Tables
-Views
-Templates
-Components
-Data Analysis
-Members
-Security
-Importing
-Exporting
-FTP
-JavaScript
-Object Model
-Full-Text Search
-Domain and Email Hosting
-HotBlock Modules
-Account Management
-Glossary
-New Responsive UI Module





DataWeb Help
Support Forums
Tutorial
Script Library
Knowledge Base

Home > Support

Support Forum



<ws:include> in templates
simlarkin asked:
I am using a double nav bar scheme in the templates for my web (w2.wacweb.org).

I would like to have one "template.view" that is used by all the pages in my web.  I would pass it a parameter that would specify which top level tab should be considered "selected".  E.g. in "default.view" I would say
   <ws:viewinfo masterpage="/Themes/template.view?tabselected=1" />

This template.view would then include the appropriate second level header e.g.
if (tabselected == 1) {
"<ws:include src='tab1secondnav.view' />
}

etc...

However, these includes don't seem to work.  For example, the template include with the "?tabselected=" seems to make the template include fail.

Any suggestions on how to do this?  In the current way I'm doing it I have 5 nearly identical templates that only differ by the tab selected and the second nav bar choices. To see what I mean, examine

w2.wacweb.org/Themes/template_home.view
w2.wacweb.org/Themes/template_link.view

This seems really inefficent.
 
  brendanx responded:
  First, allow me to agree that this should be a lot easier than it is today, and you can expect it to be in "a future release".

Now, here is something you might try to avoid the template_*.view proliferation:

The <ws:navbar> will show a tab as selected if the request URL begins with the HREF in the <a> tag. i.e.

<a href="/trips/"> will show /trips/default.view when you click the tab, but will also be selected for /trips/discussion.view, and /trips/leaders.view.

So, it seems that your template.view could look something like:

<!--#
function isTab(path)
    {
    return String.equalIgnoreCase(path, request.getRequestURI().substring(0, path.length));
    }
#-->

<ws:navbar>
   <a href="/home/default.view">Home</a>
   <a href="/classes/">Classes</a>
   <a href="/trips/">Trips</a>
   <a href="/meetings/">Meetings</a>
</ws:navbar>

<ws:htmlblock visible="#isTab('/classes/')#">
   <ws:include src="/classes/nav2.view" />
</ws:htmlblock>
<ws:htmlblock visible="#isTab('/trips/')#">
   <ws:include src="/trips/nav2.view" />
</ws:htmlblock>
<ws:htmlblock visible="#isTab('/meetings/')#">
   <ws:include src="/meetings/nav2.view" />
</ws:htmlblock>

Takes a little organization, but this actually seems pretty nice to me since it isolates each area of the web into its own subdirectory.

Okay, just to make sure this idea works, I created a sample web at:

http://level2nav.westside.com/

You can play with it there.  If you like it, you can even download a sample archive (or just create from 'http://level2nav.westside.com/level2nav.zip'), and play with the code more yourself.
 
  brendanx responded:
  DataWeb considers this issue closed.
If you have additional questions or comments about this issue, please open it again.
If you have questions about a different topic please open a new support question.

Thanks,
DataWeb Support
 
  nicks responded:
  This issue is open.  
  nicks responded:
  There is currently no straightforward way to do this.

1. You can use # substitution in the "masterpage" attribute of a view.  This is the only bit of script on the main view which is executed before the template view is executed.
This functionality allows you to dynamically determine which template view to use, but also allows you to set variables that can be used by the template view.

Each view file (includes, templates, and the main view) execute in a different scope, but they all have access to the variables that are in the global scope.  The variables in the global scope are all properties off of an object called "globals".
There are "globals.user", "globals.request",
"globals.response", etc. which are all available in script as "user", "request", and "response".
You can add your own properties to "globals".

2. In your main view, you could set the "masterpage" attribute to be the following:
<ws:viewinfo masterpage="#globals.subtabstrip='/subtabstrip1.view';'/themes/template.view';#" />
The expression:
globals.subtabstrip='/subtabstrip1.view';'/themes/template.view';
evaluates to the string:
'/themes/template.view'
which is the template you actually want to use.
It also has the side effect of creating the property "subtabstrip" to the object "globals", which the template page can actually use later.

(note that the ' characters in that expression will get escaped to &apos; when the view is saved, but they will still work correctly).

3. Then, on the template view, you could have script that checks to see if the main view has set "globals.subtabstrip", and, if not, sets it to a default value (otherwise we will be looking for a view called "undefined" in step 4)
<!--#
if (!globals.subtabstrip)
  {
  globals.subtapstrip = '/defaultsubtabstrip.view';
  }
-->

4. Furthermore, you can then have a <ws:include> tag on your template page:
<ws:include src="#globals.subtabstrip#" />
 
  tamram responded:
  DataWeb considers this issue closed.
If you have additional questions or comments about this issue, please open it again.
If you have questions about a different topic please open a new support question.

Thanks,
DataWeb Support
 
  jax responded:
  This issue is open.  
  jax responded:
  I'm trying to use the "globals" as mention by nick here, which I think is the right way to solve this problem.  However, I can't get it to work.  Did this change with 2.0 (since this was discussed back in April)?  
  simlarkin responded:
  Here's how I do it:

<ws:template="#globals.tab='thistab';'/Themes/template.view'#" />


And then in /Themes/template.view I have a function that reads the global variable and figures out the tab:

if (globals.tab == 'thistab') {

} else if (globals.tab == 'othertab) {

etc...

This is being done in V2.1 and works (see http://wacweb.org for an example)

- Sim
 
  jax responded:
  DataWeb considers this issue closed.
If you have additional questions or comments about this issue, please open it again.
If you have questions about a different topic please open a new support question.

Thanks,
DataWeb Support
 
  nicks responded:
  This issue is open.  
  nicks responded:
  In V2, there is a better way to do this.

Look at:
http://helpv2.westside.com/default.view?Topic=views/xml/vxmlparameterdecl
and
http://helpv2.westside.com/default.view?Topic=views/xml/vxmlparameter
 
  jax responded:
  I guess I'm trying to do something that can't be done.  I'm want to set a sub tab (by whatever means) have have it be persistant across hotblocks (for example). 

Consider that I have tabs "Support", "training", "developers", and each has a sub nav, and EACH has a link to the "discussion board" module (which is filtered for that group). 

User selects "Training", the "Discussion Board", and the sub nav goes away.  In other words the sub nav needs to be consistant until the "master tab" has been changed.  This shouldn't be something I have to code into EVERY view.

Am I making sense?  Or am I missing something obvious?

BTW, thanks to everyone who has given advice.
 
  nicks responded:
  I get it, I think.  It sounds like the code to figure out the sub tab should live on the template, so that it's only in one place.  Furthermore, the only way for a template to communicate information back to the view that called it is via a global variable, or a property off of some object that happens to be global.  
  jax responded:
  I finally solved it... using cookies (blech!)

I creates a .ws file with the function:

webcall function setNav(gid) {
    var cookieStr = "/" + gid + "/navbar.view";
    response.addCookie("group", cookieStr);
    response.throwRedirect("/" + gid + "/");
}

Each tab in the navbar (template.view) does something like:

<a href="Nav.ws?_fn=setnav&amp;gid=support">Support</a>

Then, later in the template.view I draw the sub navigation:

<!--#
var theSubNav = request.getCookie("group", "/navbar.view")
-->
<ws:include src="#theSubNav#" />

Which give me the persistance I'm looking for; everything is in the template.view. 

What would be ideal, however, would be a session object that I could add a global to (say, "curNavSelection") and modify in a similar way.
 
  dougl responded:
  DataWeb considers this issue closed.
If you have additional questions or comments about this issue, please open it again.
If you have questions about a different topic please open a new support question.

Thanks,
DataWeb Support
 
  Please Log On
or create your own DataWeb Account.
Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
DataWeb, 720 North 10th Street, A #145, Renton, Washington 98057 *425-583-5970* Fax 484-770-4706* Email Us