Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » LiteralField in template

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

Page: 1
Go to End
Author Topic: 1981 Views
  • freenet
    Avatar
    Community Member
    22 Posts

    LiteralField in template Link to this post

    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

  • freenet
    Avatar
    Community Member
    22 Posts

    Re: LiteralField in template Link to this post

    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

  • Exiler
    Avatar
    Community Member
    2 Posts

    Re: LiteralField in template Link to this post

    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?

  • weareorganism
    Avatar
    Community Member
    14 Posts

    Re: LiteralField in template Link to this post

    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!

  • joelg
    Avatar
    Community Member
    129 Posts

    Re: LiteralField in template Link to this post

    Thanks Weareorganism

    This worked for me...

    1981 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.