Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

LiteralField in template


Go to End


5 Posts   3531 Views

Avatar
freenet

Community Member, 22 Posts

4 February 2010 at 10:18am

sorry my noob question but I do not understand why not see in template LiteralField.

- create class MyForm
- create template in "include" folder
- use $dataFieldByName(nameLiteralField) or $nameLiteralField but nothing include in my template

DropdownField, TextField and etc normal include in template

Avatar
freenet

Community Member, 22 Posts

5 February 2010 at 2:04pm

i think i'm use not right method anyone can help me?

i'm find in \sapphire\forms\FieldSet.php function collateDataFields() if set $isIncluded = true;($field->hasData() return false is my problem) LiteralField work, but not good variants

Avatar
Exiler

Community Member, 2 Posts

7 May 2010 at 4:55am

I ran into the same problem. Every other field i needed works perfectly with $dataFieldByName(Name), but not LiteralField. Any one has a good solution?

Avatar
weareorganism

Community Member, 14 Posts

18 January 2011 at 7:23pm

Edited: 18/01/2011 7:25pm

Unless I'm missing something this seems to have been overlooked in the Form class. While there is a method to access all Data fields:

<?php
//...
getDataByFieldName(FieldName);

This function returns all fields with data and will not return literals, headings etc.
With a little creativity it is possible to circumvent the functions in the Form class and access the FieldHolder method from the FieldSet directly for these fields in your custom form template via:

<!-- In customformtemplate.ss -->
$Fields.FieldByName(YourLiteralFieldName)

Hope that helps!

Avatar
joelg

Community Member, 134 Posts

28 February 2011 at 5:07am

Thanks Weareorganism

This worked for me...