WordPress Advanced Custom Field Plugin + Twig Template
I am creating a real estate website with Realia template . This theme is based on Twig files and here is my problem. I have a front end view where we can add a custom post (property). I want to add a custom field to this form. The code that gets and displays the field is generated and works because it's in the php file;
<?php acf_form_head(); ?>
<?php acf_form( array(
'field_groups' => array(1943),
'form' => false,
) ); ?>
But now I want to save my field data and the Add My Property button is in the 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 acf_form_head()
, but I don't know how to put it in my code. I try {{ acf_form_head() }}
, {{ wp.acf_form_head() }}
and another suggestion, but nothing works ... I tried to find the "save" function that is on this php file , but I don't know how to edit it ..
Please can anyone help me?
thanks in advance
Jennifer O.
source to share
As far as I know the topic is wp-realia.
{{ }}
These tags are used to output certain things to the browser or calling methods. add wp. before calling any wp function . means that these functions are user-defined or the main function. if you call a function without wp prefix . , this means you are calling the twig template function.
{% %}
These tags are used to call kernel branch functions eg {% if my_var %}
.
For your scenario, you want to call the acf_form_head () function in the header to print the css / js and required files in the header so that you can make a block in the realia / templates / helpers / header.twig file in the main tag like:
{% block header_block %}{% endblock %}
then in your special link to the twig template file that locks and puts its 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 this helps you.
source to share