Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PrettyName on EmailTemplates #22

Closed
rafaelgimeno opened this issue Apr 1, 2016 · 4 comments
Closed

PrettyName on EmailTemplates #22

rafaelgimeno opened this issue Apr 1, 2016 · 4 comments

Comments

@rafaelgimeno
Copy link

Hi,

I think there's an error in email templates, on @field.PrettyName, the message shows the field type (eg, "Textbox") and not the pretty name (eg "Telephone").

I don't know if there is any other way to get the "Name" attribute or even the "Placeholder" attribute.

Thanks!

@kjac
Copy link
Owner

kjac commented Apr 1, 2016

Oh! Heh... funny. I'll fix that asap.

You'll want to use @field.Name instead. It should work with the current version.

@rafaelgimeno
Copy link
Author

Thanks! @field.Name works!

If it isn't difficult, it could be interesting be able to access to the "Label" attribute too (eg @field.Label).

@kjac
Copy link
Owner

kjac commented Apr 2, 2016

It's not too difficult - it's all in the API. If you've based your work on the sample email template, you'll just need to do a bit of casting.

The sample email template loops through the form value fields returned by Model.AllValueFields(). These are of type FieldWithValue, and do not necessarily have a label because the label is defined on the type FieldWithLabel (alongside the help text). However, FieldWithLabel inherits from FieldWithValue, so if you can cast the field to FieldWithLabel, you can access its label (and help text).

Try something along these lines:

@foreach (var field in Model.AllValueFields())
{
  var fieldWithLabel = field as FormEditor.Fields.FieldWithLabel;
  <tr>
    <th>@field.Name</th>
    <td>@(fieldWithLabel != null ? fieldWithLabel.Label : null)</td>
    <td>@(fieldWithLabel != null ? fieldWithLabel.HelpText : null)</td>
    <td>@field.SubmittedValueForEmail()</td>
  </tr>
}

Word of warning: I haven't tested if that code actually works, but I think it will - if nothing else it'll give you an idea of what you can do.

kjac pushed a commit that referenced this issue Apr 3, 2016
@kjac
Copy link
Owner

kjac commented Apr 3, 2016

The email template has been fixed in the latest release (0.12.0.2).

@kjac kjac closed this as completed Apr 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants