3

I'm creating a real estate website with the template Realia. This theme is based on Twig files and here's my problem. I have a front end submission where we can add a custom post ( a property ). I want to add a custom field to this form. The code which get and display the field is made and work because it is in a php file ;

<?php acf_form_head(); ?>

<?php acf_form( array(
    'field_groups' => array(1943),
    'form'  => false,
) ); ?>

But now I want to save the data of my field and the button "Add my property" is in a Twig file..

Here's the button code

      <div class="form-actions">
            {% set value = wp.__('Save', 'aviators') %}
            <input type="submit" class="btn btn-primary" value="{{ value }}">
        </div>
    {% endif %} 

</form>

According to this documentation , the acf code is acf_form_head() but I dunno how to put it in my code. I try {{ acf_form_head() }}, {{ wp.acf_form_head() }} and some other sentence but nothing works... I tried to to find the "save" function which is on this php file but I don't know to edit it..

Please, could someone help me ?

Thank in advance

Jennifer O.

Aibrean
  • 6,297
  • 1
  • 22
  • 38
Feyrisa
  • 48
  • 8

1 Answers1

2

As far as i know wp-realia theme.

{{ }}

These tags are used for outputting some thing to browser or calling methods. add wp. before calling any function wp. means that this functions is user defined or core function. if you call function without wp. prefix it means you are calling twig template function.

{% %}

These tag are used for calling core twig functions eg {% if my_var %}.

For your scenario you want to call acf_form_head() function in header to print css/js and necessary files in the header so you can make a block in the realia/templates/helpers/header.twig file in head tag eg:

{% block header_block %}{% endblock %}

then in your custom twig template file reference that block and put your content in it:

{# we tell our custom template to extends from layout.twig #} 
{% extends 'layout.twig' %}

{# Add acf_form_head() function in our header block #} 
{% block header_block %}
    {{ wp.acf_form_head() }}
{% endblock %}

{# add this content to our content block which is define in layout.twig file #} 
{% block content %}
    {% if wp.have_posts() %}
        {% for post in posts %}
            {{ wp_query.the_post() }}
            My custom field: {{ wp.the_field('my_custom_field') }}
            {{ wp.acf_form() }}
        {% endfor %}
    {% endif %}
{% endblock %}

Hope it will help you.

Touqeer Shafi
  • 5,084
  • 3
  • 28
  • 45
  • Thank for your reply. I tried `{% wp.acf_form_head() %}` but it doesn't work too... But I have a question, `acf_form_head()` is just a fonction that I have to put in the head, so in twig it is `{{ }}` or `{% %}` ? According to the [ACF documentation,](http://www.advancedcustomfields.com/resources/create-a-front-end-form/) it does nothing Do you have an idea ? – Feyrisa May 19 '15 at 07:52