[stringtemplate-interest] Is there way to calltemplatesfromanother group without inheritance?

Dreyer Ulf (CR/APA3) Ulf.Dreyer at de.bosch.com
Fri Sep 14 02:28:42 PDT 2007


Hello Florin,


thanks again for the links and the input.
I will probably override the template-resolution within
ST to keep the actual syntax simple. 
( $someMapping.("somePath")(SomeParam=SomethingElse) seems rather a mouthfull)

I can't get on this right away though so it may be
some time before I get back to the list with my findings. 

-Ulf

-----Ursprüngliche Nachricht-----
Von: stringtemplate-interest-bounces at antlr.org [mailto:stringtemplate-interest-bounces at antlr.org] Im Auftrag von Florin T.PATRASCU
Gesendet: Freitag, 14. September 2007 02:28
An: StringTemplate
Betreff: Re: [stringtemplate-interest] Is there way to calltemplatesfromanother group without inheritance?

Hi Ulf,

Indeed you can't call ST files from a different group than the  
caller's own unless you use inheritance. You may want to read this  
article for a similar topic:
http://hardlikesoftware.com/weblog/2007/06/25/thoughts-on- 
stringtemplate-part-2/

However, with JP, your example will not have problems running because  
the templates are calling other templates through a Repository manager.

So, following your example, let's say you're defining two JP  
Repositories. One mapped on the sub1 directory and called "sub1" and  
another repository mapped on the sub2 directory and called "sub2".  
These repositories will be defined in the JP's own configuration file  
(jpublish.xml):
...
     <repository name="sub1"  
classname="org.jpublish.repository.filesystem.FileSystemRepository">
         <root>sub1</root>
         <cache>default</cache>
     </repository>

     <repository name="sub2"  
classname="org.jpublish.repository.filesystem.FileSystemRepository">
         <root>sub2</root>
         <cache>default</cache>
     </repository>
...

And because all the repositories are injected in the template's  
context by JP at the rendering time, all the templates will have  
access to any repository.

So, for example you can call template3.st from template1.st as simple  
as this:
(excerpt from template1.st)
...
$sub2.("template3.st")$
...

and the above will work in JP :)

If this approach is suitable for your problem but JP is not  
applicable, I believe you can easily create your own "repository"  
manager and use it to load and render the ST files. Have a look at  
the StringTemplate Standalone Tool (STST), same blog: http:// 
hardlikesoftware.com/weblog/stst/

my 0.02CAD
-florin


On 13-Sep-07, at 08:22 , Dreyer Ulf (CR/APA3) wrote:

> Hi Florin,
>
>  I just re-read your first post. I think I misunderstood you.
>  For clarification:
>
>  -) you define .st-files in different Folders
>     like:
>
>     root\
>          |---sub1\
>          |    + template1
>          |    - template2
>          |
>          |
>          ----sub2\
>             -template3
>    correct?
>
>  -) you then create 1 Templategroup or 3 groups?
>
>  I have the problem that template3 may have the same name as  
> template2.
>  So I can't have only one templategroup. But as far as I know you  
> can't call into another templategroup
>   you don't inherit.
> -Ulf
>
> Von: stringtemplate-interest-bounces at antlr.org  
> [mailto:stringtemplate-interest-bounces at antlr.org] Im Auftrag von  
> Florin T.PATRASCU
> Gesendet: Donnerstag, 13. September 2007 14:13
> An: StringTemplate
> Betreff: Re: [stringtemplate-interest] Is there way to call  
> templatesfromanother group without inheritance?
>
> Hi Ulf - I don't think I can have this issue?! In my simple  
> implementation, the ST files are treated as web pages, so they have  
> to be unique per folder, and obviously they can be nested as any  
> other ordinary directory/file. Or maybe I misunderstand you question?
>
> V/r,
> -florin
>
>
> On 13-Sep-07, at 08:01 , Dreyer Ulf (CR/APA3) wrote:
>
>> Hi Florin,
>>
>>
>> thanks for your answer. My goal is not web development but I will  
>> look into your solution.
>> One question though: How do you handle name collisions within  
>> templates?
>>
>> - Ulf
>>
>> Von: stringtemplate-interest-bounces at antlr.org  
>> [mailto:stringtemplate-interest-bounces at antlr.org] Im Auftrag von  
>> Florin T.PATRASCU
>> Gesendet: Mittwoch, 12. September 2007 14:57
>> An: StringTemplate
>> Betreff: Re: [stringtemplate-interest] Is there way to call  
>> templates fromanother group without inheritance?
>>
>> Hi Ulf,
>>
>> If your goal is to use ST for web development, I can recommend you  
>> to have a look at our project JPublish (http://www.jpublish.org)  
>> and the recently added String Template support.
>>
>> So, to your example, with JP you can define many Repositories  
>> (folders on disk, tables in a db, etc) where you can store  
>> individual ST files. JP then will create for you a ST Group for  
>> every defined Repository, pointing to the repository path.
>>
>> After that, your colleagues can reuse each other's templates by  
>> specifying the repository name and the name of the ST file they  
>> want to use and combine them to obtain simple/complex web pages.  
>> Example:
>>
>>    $my_repository.( page.Path)$
>>
>> For the line above, JP will use the ST rendering engine to render  
>> the ST files but it will also execute the JP Actions associated  
>> with the ST files (Java classes, Beanshell, Jython, JRuby or  
>> Groovy) to glue in the logic before rendering a template or after  
>> rendering it:)
>>
>> The entire JP development philosophy relies on templates and  
>> modularity. This is why we believe ST is very appropriate for JP.
>>
>> There is a ready to go JP simple project demonstrating the  
>> StringTemplate integration. You can find it archived here: http:// 
>> jpublish.googlecode.com/files/stdemo.war.zip, in case you want to  
>> give it a try.
>>
>> I hope it helps.
>>
>> V/r
>> -florin
>>
>>
>> On 11-Sep-07, at 08:22 , Dreyer Ulf (CR/APA3) wrote:
>>
>>> Hi,
>>>
>>>  I'm working on a system where the user (not necessarily an  
>>> accomplished developer)
>>>  can write own templates / templategroups.
>>>  I'd like them to be able to call other templates in different  
>>> groups without using
>>>  inheritance.
>>>
>>>  Example:  user A writes a template group that generates   
>>> Component A ( or Webpage A or whatever)
>>>                  user B writes a template group that generates   
>>> Component B ( or Webpage A or whatever)
>>>
>>>  now User C would like to write a template with the output   A; B.
>>>  Preferably by writing something like   combinedTemplates :== <<  
>>> <A.main()>; <B.main()> >>
>>>  (Assuming "main" is the generating template in groups A and B)
>>>
>>>  If I'm correct this is
>>>
>>>  a) not possible if neither group A nor group B inherit from one  
>>> another.
>>>
>>>  b) possible if B inherits from A but ONLY if C inherits B and  
>>> none of them uses
>>>      the same names for templates.
>>>
>>>  Is there an way to handle this nicely?
>>>
>>>  My idea would be to mangle the names of the templates with their
>>>  group and create a temporary group containing all templates.  
>>> This solution will very likly turn out to be messy.
>>>
>>>
>>> Ulf
>>>


More information about the stringtemplate-interest mailing list