Note that there are some explanatory texts on larger screens.

plurals
  1. PORails-style template helpers in Velocity
    primarykey
    data
    text
    <p>I need to add a number of really complex dynamic HTML structures to my Velocity template. If I were to attempt to write these directly in the template, it would be an absolute mess.</p> <p>Let me explain what I'm trying to do... let's say, on my website, a user can post comments. Rather than writing all the complex dynamic HTML structure that goes into the comments table and the posting form, I would like to be able to do this in my template:</p> <pre><code>&lt;div&gt; // call to a method that generates the comments table &lt;/div&gt; &lt;div&gt; // call to a method that generates the comments form &lt;/div&gt; </code></pre> <p>In Ruby On Rails, there are things called <a href="http://paulsturgess.co.uk/articles/show/49-using-helper-methods-in-ruby-on-rails" rel="nofollow">helpers</a> that allow you, from the templates, to call, basically, a method that returns a dynamically-generated chunk of HTML, to be embedded in the template right where you call it. The nice thing about helpers is that you only spend CPU on the ones you use. With the <code>VelocityContext.put()</code> method, it seems like I have to generate everything I need in advance. This is a problem because I will ultimately have some 50 different helpers, and I need the non-programmer web designer to be able to swap them in and out at will.</p> <p>So I am asking,</p> <ol> <li>Can I do something like this with Velocity?</li> <li>If not, can I do something like this with some other template engine?</li> <li>Is there a better way to do what I'm trying to do?</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload