You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@forrest.apache.org by Thorsten Scherler <th...@apache.org> on 2005/06/22 10:32:14 UTC

logic:filter (was Re: Can I have two 'views' of a site?)

Moved to dev (without copy to user) because this is dev pure. ;-)

On Tue, 2005-06-21 at 11:06 +0100, Ross Gardler wrote:
> Thorsten Scherler wrote:
> > On Fri, 2005-06-17 at 14:50 -0400, Paterline, David L. wrote:
> > 
> >>Hello -
> >>
> >>I'm a new user of Forrest, and am investigating its use as an interface for
> >>our online computer code documentation. Unfortunately, we will need two
> >>different 'views' of the site - one for internal users and a second, more
> >>restricted version for external users.
> >>
> >>Simply put, there will be some information (some links) which we only wish
> >>to show to our internal users.
> >>
> >>I'm hoping to be able to generate these two views without duplicating
> >>information, to minimize maintenance cost and errors.
> >>
> >>So, my question is, can I somehow mark certain portions of the information,
> >>then do two builds - one for internal, with "include=all" and one for
> >>external with "exclude=somestuff"?
> >>
> > 
> > 
> > I am answering you because you said you are in the process of evaluating
> > forrest. What I am going to write is *not* fully included in the 0.7
> > release (it is in the whiteboard) but will hopefully go officially into
> > 0.8.
> 
> Please, please, please can you provide an example or a brief document 
> for this when you get the time. I have a use case that I would like to 
> address in the next couple of weeks and was going to go with the two 
> site.xml files and a request parameter to select between them. Since the 
> site is views based I'd like to try out this new method.

Ok, the basic idea that I have for this use case is to use the infamous
logic: tag to have simple conditions that decide to include some
contracts or not.

The idea is to extend the "prepare.view.xsl" from the internal.view
plugin. This xslt we can extend for this condition. 

I have an old use case on which I want to explain what I mean. I needed
to make the processing page specific with the help of a variable last
page, that contains the max pages of the document:

In my view I added:
      <forrest:hook name="page" count="4">
        <logic:lastPage value="4">
          <forrest:contract type="img" name="top-image-bit-last"
objectId="411"/>
          <forrest:contract type="txt" name="footer-l-text"
objectId="441"/>
        </logic:lastPage>
        <logic:lastPage value="8">
          <forrest:contract type="img" name="top-image-bit"
objectId="411"/>
          <forrest:contract type="txt" name="footer-r-text"
objectId="441"/>
        </logic:lastPage>
        <forrest:fbits name="infobits" count="4"/>
      </forrest:hook>

Now in the "prepare.view.xsl" from the internal.view I added first the
variable for the lastPage:
<xsl:variable name="lastPage" select="count($model/folder/page)"/>

and then matched the logic tag:
  <xsl:template match="logic:lastPage">
    <xsl:comment>logic tag value: <xsl:value-of select="@value"/>
</xsl:comment>
    <xsl:if test="@value=$lastPage">
      <xsl:apply-templates/>
    </xsl:if>
  </xsl:template>

You see this example is *very* usecase specific and we need something
more flexible. To make it more flexible we need a mechanism where we can
define the needed variables like <xsl:variable name="lastPage"
select="count($model/folder/page)"/> in a view specific way. 

I mean something like 
<logic:filter name="role" value="user"/>

and in the "prepare.view.xsl"
<xsl:variable name="role" select="$model/session/role"/>

  <xsl:template match="logic:filter">
    <xsl:comment>logic tag <xsl:value-of select="@name"/> value:
<xsl:value-of select="@value"/> </xsl:comment>
    <xsl:if test="@value=$role">
      <xsl:apply-templates/>
    </xsl:if>
  </xsl:template>

...but that would look into the model and expect the xpath /session/role
in the presentation model. That means that we need to extend the model
with this information in an earlier stage.

This is just an idea who we can do it actually I reckon you may suggest
some enhancements and I will give it a go and make an example with your
use case.

The question we need to resolve how can we easily extend the logic
conditions?

WDYT?

salu2
-- 
thorsten

"Together we stand, divided we fall!" 
Hey you (Pink Floyd)