forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thorsten Scherler <thors...@apache.org>
Subject Re: Best way to add repeatable code in v2/v3 (was Re: Example use case)
Date Sun, 22 Jan 2006 17:19:56 GMT
El sáb, 21-01-2006 a las 20:06 +0800, Gav.... escribió: 
> Hi All,
> 
> On the right hand side of http://minitutorials.com I have some 'headlines' 
> in a 'headlines' div
> All boxes are in a 'rightbar' div also.
> The code for this is in One file called rightnav.ssi and included using 
> either 'include' or 'require'
> This obviously has the effect that all of the site pages get the content 
> from the one file.
> 
> I have been looking at how to do this using dispatcher method.
> 
> What I have tried :-
> 
> 1. Create Hooks as required to get the div and css to position it.
> 
>  <forrest:hook name="headlines">
>    <forrest:hook name="rightbar">
>      <forrest:contract name="search-input">
>             <forrest:properties contract="search-input">
>               <forrest:property name="search-input">
>                 <search name="minitutorials" domain="www.minitutorials.com" 
> provider="google"/>
>               </forrest:property>
>             </forrest:properties>
>     </forrest:contract>
>   </forrest:hook>
>   </forrest:hook>
> 
> As you can see I have added a search-input so the div shows on the site and 
> is present at http://apache.minitutorials.com

yeah, nice.

> 
> 2. Then I looked through ls.contracts and found one I thought might be 
> suitable as replacement of 'include/require'
> Adding the code for it into my hooks above I ended up with :-
> 
>  <forrest:hook name="headlines">
>    <forrest:hook name="rightbar">
>      <forrest:contract name="search-input">
>             <forrest:properties contract="search-input">
>               <forrest:property name="search-input">
>                 <search name="minitutorials" domain="www.minitutorials.com" 
> provider="google"/>
>               </forrest:property>
>             </forrest:properties>
>     </forrest:contract>
> <forrest:contract name="content-include-html">
>     <forrest:properties contract="content-include-html">
>       <forrest:property name="content-include-html" 
> nugget="get.nugget.include.html">
>        <url>/rightbar.html</url>
>       </forrest:property>
>     </forrest:properties>
> </forrest:contract>
>   </forrest:hook>
>   </forrest:hook>
> 
> (content-include sounds just what I need)

Hmm, not directly. 
1) it is a v1 contract. <url>/rightbar.html</url> is not aviable
anymore. This have to be done with jx:import.
2) the syntax you use expects rightbar.html *not* in the docroot but the
the file path /rightbar.html!

> 
> 3. The html code required I transfered from rightnav.ssi into rightnav.html 
> and put this file
> into xdocs directory. I am hoping that the <url>/rightbar.html</url> is 
> therefore correct.

no, see above

> 
> 4. Didn't see what else I would need to do, so did a 'forrest run' , did not 
> show up.
>     Also did a ForrestBot onto the web server, also does not show up.
> 
> So, this did not work, the question is, have I done something wrong, missed 
> something out
> or is there a different/better way to include content into the 'headlines' 
> hook ?
> 

<forrest:contract name="content-include-html">
    <forrest:properties contract="content-include-html">
      <forrest:property name="content-include-html"
nugget="get.nugget.include.html">
        <jx:import uri="cocoon://includes.rightbar.html"/>
      </forrest:property>
    </forrest:properties>
</forrest:contract>

...but be aware that this contract expect a <div id="content"/>:
<xsl:copy-of select="$content-include-html//div[@id='content']/*"/>

> Alternative I thought of would be to create a contract for it. Although I 
> can see how to
> create a contract, not sure again on the best way of approaching it. Maybe 
> doing a similar
> thing as including the body from say index.xml but using 
> rightnavcontent.xml, use jx: ??
> 

Actually I think in your case it would makes sense to create a contract.

Now you have different options to implement it. 

1) controlled by the structurer 
You can use the genericMarkup.ft
<forrest:contract name="genericMarkup">
 <forrest:properties contract="genericMarkup">
  <forrest:property name="genericMarkup">
   <div class="rightsub">
    <h5>Sponsor This Site!</h5>
   </div>
  </forrest:property>
 </forrest:properties>
</forrest:contract>

You would do this if the code is added to all pages and actually does
not change too much. As soon as you change it on a regular basis and
would need to have different code on different pages it makes sense to

2) create a custom business service
A custom business service is an extension of forrest core data models.
In the dataModel.xmap you can find the core models. You can add your own
service to your project sitemap. Like:
<map:match pattern="includes.rightbar.**.xml">
 <map:generate src="{project:resources}/includes/rightbar/{1}.xml" />
 <map:serialize type="xml"/>
</map:match>

This assumes that you move to xml instead of html output (remember you
can use html like grammar in xml).

Now you could define the contract like:
<forrest:contract name="content-include-rightbar">
    <forrest:properties contract="content-include-rightbar">
      <forrest:property name="content-include-rightbar"
nugget="get.nugget.include.rightbar">
        <jx:import
uri="cocoon://includes.rightbar.#{$cocoon/parameters/getRequest}.xml"/>
      </forrest:property>
    </forrest:properties>
</forrest:contract>

and the contract:
      <xsl:template name="content-include-rightbar-body" >
        <xsl:param name="content-include-rightbar"/>
        <xsl:copy-of 
          select="$content-include-rightbar/*"/>
      </xsl:template>
3) ...

I can actually think on a couple of other ways how to include extra stuff but it always depend
on the usecase.
Questions like:
- is the content request aware?
- does it makes sense to create a custom business service?
- will the content included and actually never changed?
- do you need a contract that you can reuse in different projects?
- how generic the contract has to be?
....

HTH
salu2
-- 
thorsten

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


Mime
View raw message