3 Replies Latest reply on Dec 20, 2007 2:19 PM by jdelaney

    customizing presenter template/ftls - options?





      So document.ftl renders all the document content in the beige box just by outputting the $ property accessor from DocumentAction which gets built up from the template builder methods in DbDocumentPresenter.  Is the only way to customize the look/data of the document is to create classes\com\jivesoftware\community\impl\template dir in our WEB-INF and then just have customized ftls with the same name there?  I've done this and it works but I'm wondering if there is another simpler way that could be used (like the way in which we can overwrite non-presenter ftls through xwork-plugin/community.xml since the presenter ftls are the only ftls it seems "hidden" away in the class packages) or perhaps could be put in the roadmap with your custom document type creation that you're working on for 2.0 to hook into the presentation layer for the document.  Or perhaps you could just break up $ into components somehow on document.ftl so we just have to mess with document.ftl and that's it (luckily doc-create.ftl has all of its components broken up nicely so customization was simple on that).



      Some of this can be gotten around by messing with the body and injecting data in on create/edit posting that gets saved to body (so it's rendered on viewing from presenter-body.ftl's call to document.body) but then gets filtered out on edit, but this approach can only go so far if layout/styling and data requirements get very complex which would require somehow modifying the presentation layer of the document content.  If the way you planned for this scenario is indeed to simply copy classes\com\jivesoftware\community\impl\template to WEB-INF\ and override whatever presenter ftls you want, that's fine and not the end of the world but just wanted to confirm that's the way to do it and see if there were any other current (or future/tentative) options in customizing it.



      Thanks for any info.



        • Re: customizing presenter template/ftls - options?

          hi James,


          The only way you can do it in the 1.x branch (IIRC) is to put your custom FTL's in the classes\com\jivesoftware\community\impl\template directory like you mentioned. I'll push this thread around internally and find out if there are plans for improving this in 2.0, and if not, what the best course of action would be for you.





            • Re: customizing presenter template/ftls - options?


              Cool AJ - I actually have a bit of an issue dong it this way.  I need to add a custom object to the presenter template root map so that I can use it in one of the presenter ftls.  I see in DocumentAction in execute there is content = getDocument().getDocumentType().getDocumentPresenter().getTransformedTemplate(getDocument(), getAuthToken(), getLocale());



              From what I can tell, extraTemplateInfo in DbDocumentPresenter is supposed to be used for adding objects in a subclass - but really all I want to do is keep all the current default presenter behavior and just have access to this extra object in the ftl - the default presenter is a static reference to dbdocpresenter so i don't think that will be useful in a subclass since it would use dbdocpresenter's null templateinfo map and I'd rather not have to implement the entire docpresenter interface (I'm not even sure how I would as I'm not sure what exactly the documentpresenterbean is that I would have to pass into the constructor in order to get a reference I could use in DocumentAction since I am not extending/overriding document or documentType which is why I just need default behavior + adding the custom templateInfo map).



              So basically I'm just wondering how I would be able to add some custom object so that in one of the presenter ftls I can just call ${customobj.method()} - hopefully without a huge amount of complexity.  Thanks for any info.



                • Re: customizing presenter template/ftls - options?

                  Ok got this working - since dbdocumentpresenter has a private no-arg constructor, makes things a little more cumbersome when extending it but in custom documentaction, you can just create a docpresenterbean just like the one created in defaultpresenter's constructor and pass it to your subclass constructor (since it is extending dbdocpresenter and the only public constructor from dbdocpresenter takes in a  docpresenterbean) in order to get default presenter behavior.  Then in your subclass also override extraTemplateInfo map to add in your custom objects and then in documentaction you can just use content=customdbdocpresenterobj.getTransformedTemplate and the presenter ftl's will have access to your objects.  Ideally in a future release maybe jive can have a setter method or something in documentpresenter that can be used to set the extraTemplateInfo map before calling getTransformedTemplate() so users don't have to go the route of subclassing dbdocpresenter and dealing with getting around the private constructor just to add objects to the freemarker map.