Page 1 of 1

Front End Users - template variable names?

Posted: Mon Jun 29, 2015 2:37 pm
by Simon66
I'm trying to write a custom template for the 'Change Setting Template' in FEU.

The sample template loops through the controls with:

Code: Select all

{foreach $controls as $key=>$field}
But I'm trying to access them individually, and I've tried:

Code: Select all

$controls->username.prompt.value
$controls->username.prompt
$controls->fieldsbyname.username.prompt.value
$controls->fieldsbyname.username.prompt
$field->username.prompt.value
$field->username.prompt
$field->fieldsbyname.username.prompt.value
$field->fieldsbyname.username.prompt
Is there a method to working this out?
Different modules have different ways of defining individual variable names. Could this be unified across modules?

Re: Front End Users - template variable names?

Posted: Mon Jun 29, 2015 3:39 pm
by JohnnyB
This will give you the custom field's prop name.

$field->propname

So, if you have a "First Name" Prompt that was assigned a Name with first_name, you can do something like:

Code: Select all

{foreach $controls as $key=>$field}
		{if $field->propname == 'first_name'}
// Put tags/HTML for label and input fields
{/if}
{/foreach}
In one of my FEU change settings template that has over 100 property fields and somewhat complex form layout, I am using multiple {foreach $controls as $key=>$field} loops to control the layout and grouping of input fields.

Best way to know what template variables are available is to do something like

{foreach $controls as $key=>$field}
<pre>{$field|print_r}</pre>
{/foreach}

Re: Front End Users - template variable names?

Posted: Tue Jun 30, 2015 12:33 am
by Simon66
This is awesome, thanks. I was close to beating my head against a wall last night.

As I don't write code I don't know if this is a stupid question. But would it be possible to unify individual variable calls so they're the same across all modules?

Like this:

Code: Select all

$image->fieldname.value
$entry->fieldname.value
$item->fieldname.value
Simon66

Re: Front End Users - template variable names?

Posted: Tue Jun 30, 2015 2:11 pm
by JohnnyB
No, not a stupid question. I suppose it could be somewhat possible, but not probably not realistic. I just usually do the {$the_module_var|print_r} or use {get_template_vars} when using a module for the first time to see what data is available and how to access it from the arrays.