Does anyone know how to insert a custom fields (from Advanced Custom Fields plugin) into a twig template?
This is the code I want to add into the twig file.
<img src="<?php the_field('profile_pic'); ?>" />
And this is the coding of the Twig template file
{% extends 'layout - tlt.twig' %}
{% block content %}
<br> <br>
<h1 style="font-weight:bold; font-size:24px;" class="">{{ post.post_title }}</h1>
<br> <br>
<div class="agent">
<div class="row">
<div class="image span2">
<a href="{{ wp.get_permalink(wp.get_the_ID()) }}">
{% if wp.get_the_post_thumbnail(wp.get_the_ID()) %}
{{ wp.get_the_post_thumbnail(wp.get_the_ID())|raw }}
{% else %}
<img src="{{ wp.get_template_directory_uri() }}/assets/img/agent-tmp.png" alt="{{ property.post_title }}">
{% endif %}
</a>
</div><!-- /.image -->
<div class="body span4">
{{ wp.do_shortcode(wp.apply_filters('the_content', post.post_content))|raw }}
</div><!-- /.body -->
<div class="info span3">
<div style="font-size:14px;" class="box">
<div style="margin-bottom:7px;" class="phone">
<i class="icon icon-normal-mobile-phone"></i>
{{ wp.get_post_meta(wp.get_the_ID(), '_tlt_mobile', TRUE) }}
</div><!-- /.phone -->
<div style="margin-bottom:7px;" class="office">
<i class="icon icon-normal-phone"></i>
{{ wp.get_post_meta(wp.get_the_ID(), '_tlt_phone', TRUE) }}
</div><!-- /.office -->
<div style="margin-bottom:7px;" class="email">
<i class="icon icon-normal-mail"></i>
<a href="mailto:{{ wp.get_post_meta(wp.get_the_ID(), '_tlt_email', TRUE) }}">
{{ wp.get_post_meta(wp.get_the_ID(), '_tlt_email', TRUE) }}
</a>
</div><!-- /.email -->
<div style="margin-bottom:7px;" class="location">
<i class="icon icon-normal-phone"></i>
{{ wp.get_post_meta(wp.get_the_ID(), '_tlt_location', TRUE) }}
</div><!-- /.office -->
<div style="margin-bottom:7px;" class="location">
<i class="icon icon-normal-phone"></i>
{{ wp.get_post_meta(wp.get_the_ID(), 'contact_number', TRUE) }}
</div><!-- /.office -->
<div style="margin-bottom:7px;" class="location">
<img src="{{ wp.get_post_meta(wp.get_the_ID(), 'profile_pic', TRUE)}}" alt="image" />
</div><!-- /.office -->
</div><!-- /.box -->
</div><!-- /.info -->
</div><!-- /.row -->
</div><!-- /.agent -->
{% if properties %}
<hr>
{% endif %}
{% endblock %}
I did everything correctly up to inserting the code in the .twig file. Nothing worked.
I don’t use Twig, but I’m fairly sure that you have to pass values rather than all WP functions from the template (which probably runs outside the context of WordPress). So, your controller (typically the WordPress template) will store the results of the WP calls into an array, and then you render the Twig template with the values stored in the array.
[edited to add]
You have in your controller a call as follows:
Change to something like this:
And then in your Twig template, you can add something like:
<img src = '{{profile_pic}}'>