Hello,
Is there any way to get an "eval"-like behavior in Velocity. Basically,
I am looping to build an
HTML form and reading scraps of HTML from the database to populate it.
These scraps include their own Velocity directives. Here's my template:
<form name="editForm" action="editModule" method="POST">
#foreach ($field in $module.fields)
$field.fieldClass.inputBlock
#end
<input type="submit" value="Update">
<input type="hidden" name="moduleId" value="$moduleId">
<input type="hidden" name="classId" value="$classId">
</form>
Since Velocity is treating these as text rather than parsable fragments,
I get something like this:
<form name="editForm" action="editModule" method="POST">
<h3>$field.name</h3>
<textarea name="$field.id">
$field.value
</textarea>
<h3>$field.name</h3>
<textarea name="$field.id">
$field.value
</textarea>
<input type="submit" value="Update">
<input type="hidden" name="moduleId" value="$moduleId">
<input type="hidden" name="classId" value="ProductDescription">
</form>
rather than having $field.name substituted based on the value of $field
in the foreach loop.
Basically, I need to be able to #parse and pass a string rather than the
name of a template.
Is there any way to do this? If not, I will probably try to hack
something together for the short-term,
but I think it's a useful thing to have. It might look like this:
<form name="editForm" action="editModule" method="POST">
#foreach ($field in $module.fields)
#eval ($field.fieldClass.inputBlock)
#end
<input type="submit" value="Update">
<input type="hidden" name="moduleId" value="$moduleId">
<input type="hidden" name="classId" value="$classId">
</form>
--kd