2 Replies Latest reply on Jul 18, 2014 11:52 AM by Aaron Anderson

    Errai UI templating: omit or inline content

    Aaron Anderson Newbie

      I purchased a bootstrap theme and I am working on reformatting the provided HTML and mustache files to function with Errai UI templating. There are two scenarios that I have come across that I couldn't find a way to implement using Errai templating:

       

      1. Omitting/skipping an element - Is there a way to specify in the UI template to omit/skip an element if it is not mapped to a DataField? For example, given this template
        Should always be rendered
        Should only be rendered if another GWT widget is explicitly bound to it

        I would like it so that if the template class mapped to this content

        @Templated
        public class Content extends Composite{
        
        }
        

        it would produce the output

        Should always be rendered

        right now I am dealing with this by mapping an empty SimplePanel or HTMLPanel to the data-field

         

        @Templated
        public class Content extends Composite{
        @DataField("conditional")
          SimplePanel conditional = new SimplePanel();
        
        }
        
        

        but it still outputs the element and any associated styling which is undesirable. I am aware of the data-role="dummy" metadata but that just removes the children and not the element itself.

         

        Should always be rendered
      2. Inlining content - similarly is there a way to omit the root element and inline the child content? for example, given these templates and classes
      some content

       

      1. one
      2. two

       

      @Templated
      public class Container extends Composite{
      @Inject
      @DataField("placeholder")
        Contents contents;
      }
      

       

      @Templated
      public class Contents extends Composite{
      }
      

      I would like to see the output

       

      some content
      • one
      • two

       

      This capability would be extremely helpful for mustache templates where there is a mustache inclusion statement for content and I would like to replace it by injecting content from another Errai template file without introducing a new wrapper element.

        • 1. Re: Errai UI templating: omit or inline content
          Christian Sadilek Master

          Hi Aaron,

           

          Both sound like good features to me that we don't currently support. Unfortunately, the template snippets you pasted rendered as actual HTML so I am not 100% sure. Can you create two JIRAs for these features with an example?

           

          Thanks,

          Christian

          1 of 1 people found this helpful
          • 2. Re: Errai UI templating: omit or inline content
            Aaron Anderson Newbie

            I discovered that Errai UI template merging partially accomplishes what I was looking for. If I had a template nav.html that contained the following HTML snippet:

             

            <span data-field="account-id">
              <small>Account</small>
              AccountId
              </span>
            

             

            Due to Errai template merging I can manipulate the template DOM as desired:

             

            @Templated(LayoutTemplates.NAVBAR + "#account")
            public class Account extends Composite {
            
            
                @DataField("account-id")
                Element accountId = Document.get().createSpanElement();
            
            
               
                
                public void init(User user) {
                    Window.alert(accountId.getChildCount() + " -> " +((Text)accountId.getChild(2)).getData());
                    ((Text)accountId.getChild(2)).setData(user.getIdentifier());
                    
                }
            }
            

             

            Presumptuously manipulating the template DOM in Errai may not be the best practice since because if the template is modified the DOM manipulation code may silently error out. However this leads to the larger general design question with Errai: how much static content is generated in Java/GWT versus what how much is maintained in templates.