This is my first question on stackoverflow.
I have a problem with ACF and Timber. I have created an ACF group like this :
My acf group
I want to check if type_pre-footer = XXX,so in my Twig template I have made this :
{% if post.meta('pre-footer').type_pre-footer == 'Titre et liens' %}
<section class="join-us">
<img src="https://picsum.photos/1800/537" class="alwaysgray" alt="">
<div class="top-right">
<h5>Rejoignez-nous !</h5>
<ul>
<li>{{ macros.svg('arrow','12','as--white', assetsDir) }}
Offres d'emploi</li>
<li>{{ macros.svg('arrow','12','as--white', assetsDir) }}
Candidature spontanée</li>
<li>{{ macros.svg('arrow','12','as--white', assetsDir) }}
Recrutement d'équipes</li>
</ul>
</div>
...
But it's not working, I have tried to display post.meta('pre-footer').type_pre-footer with a {{dump()}, but it return 'int(0)'. When I try to display only post.meta('pre-footer'), it return an array :
array(3) {
["type_pre-footer"]=> string(14) "Titre et liens"
["titreliens"]=> array(3) { ["titre"]=> string(0) "" ["liens"]=> bool(false) ["image"]=> string(0) "" }
["articles"]=> array(2) { ["titre"]=> string(0) "" ["articles"]=> bool(false) } }
have you any idea about how to solve it ?
if you need more logs, you can ask me, thanks
Related
I'm trying to get a parent level custom taxonomy category name to output to an h6 tag, and I also need to get the child category name and output it in an h5 tag. I thought it would be simple by just accessing the index of the get_terms array, but the return doesn't seem to be consistent. Any suggestions would be greatly apprececiated. Is there a more efficient way to get a parent category, and a child category for a post?
$terms = get_the_terms( $post->ID , 'news-categories' );
if(count($terms) > 1) {
echo '<h5><i class="fas fa-tag"></i> ' . $terms[0]->name . '</h5>';
echo '<h6><i class="fas fa-tag"></i> ' . $terms[1]->name . '</h6>';
}
Here's a var_dump of the output of terms
array(2) {
[0]=>
object(WP_Term)#2985 (10) {
["term_id"]=>
int(45)
["name"]=>
string(17) "Project Spotlight"
["slug"]=>
string(17) "project-spotlight"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(45)
["taxonomy"]=>
string(15) "news-categories"
["description"]=>
string(0) ""
["parent"]=>
int(0)
["count"]=>
int(87)
["filter"]=>
string(3) "raw"
}
[1]=>
object(WP_Term)#2965 (10) {
["term_id"]=>
int(47)
["name"]=>
string(22) "Workforce Preparedness"
["slug"]=>
string(22) "workforce-preparedness"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(47)
["taxonomy"]=>
string(15) "news-categories"
["description"]=>
string(0) ""
["parent"]=>
int(45)
["count"]=>
int(37)
["filter"]=>
string(3) "raw"
}
}
Just as a note "Project Spotlight" should always show as the parent and "Workforce Preparedness" should return as the child, however, it's inconsistent on some posts.
I'm having issues with file uploads... I'm adding manually a few inputs within a Symfony form (Offer) to allow the user to create a new Company if he doesn't want to use one that already exists, it works very well for the text/textarea fields, but my file Input doesn't work properly. Its content appears in the request parameters instead of in the files parameters of my Request, see below what I get when I dump($request) :
OfferController.php on line 173:
Request {#86 ▼
+attributes: ParameterBag {#70 ▶}
+request: ParameterBag {#69 ▼
#parameters: array:2 [▼
"offer" => array:15 [▶]
"company" => array:6 [▼
"name" => "entreprise"
"pic_logo" => "ah.png" //THIS SHOULD NOT BE HERE BUT IN THE FILEBAG
"sector" => "2"
"status" => "fdsfds"
"revenues" => "sdfsdf"
"content" => "<p>sdfdsf</p>\r\n"
]
]
}
+query: ParameterBag {#49 ▶}
+server: ServerBag {#73 ▶}
+files: FileBag {#63 ▼
#parameters: [] //NO FILE HERE :'(
}
Here is the code that produces this :
View :
{{ form_start(form) }}
<h2>Employeur</h2>
{{ form_row(form.company) }}
<a class="company-new" href="#" id="toggleCompanyForm">Ajouter une nouvelle entreprise...</a>
<div id="form_company" style="display:none">
<div class="row">
<div class="large-6 small-12">
<label>Nom de l'entreprise</label>
<input type="text" name="company[name]">
</div>
<div class="large-6 small-12">
<label>Logo de l'entreprise</label>
{% for message in app.session.flashBag.get('warning_logo') %}
<div class="alert alert-warning">
{{ message }}
</div>
{% endfor %}
<input type="file" name="company[pic_logo]"> {# MY FILE INPUT #}
</div>
And the controller :
public function createAction(Request $request)
{
$confirmed = false;
$entity = new Offer();
$em = $this->getDoctrine()->getManager();
$sectors = $em->getRepository('ModelBundle:Sector')->findAll();
$form = $this->createForm('ModelBundle\Form\OfferType', $entity);
$session = $request->getSession();
die(dump($request));
To upload a file through HTML form you have to add enctype="multipart/form-data" to the tag:
<form action="..." method="post" enctype="multipart/form-data">
Or change opening form tag in twig:
{{ form_start(form, {'multipart': true}) }}
I have a twig template where I am displaying certain details based on the type of person.
But the condition is not working, I'm just wondering what is wrong with the IF clause?
{% if field_person_type == 'XXXXXXX' %}{{ (content.field_position) }}, {{ (content.field_unit) }}
{% else %} {{ (content.field_position) }}, {{ (content.field_institution) }} {% endif %}
And the content is defined below
Position field_position Text Text field
Person Type field_person_type Term reference Check boxes/radio buttons
Unit field_unit Text Text field
Institution field_institution Term reference Check boxes/radio buttons
When I use dump(field_person_type), it shows following
ARRAY(1) {
[0]=> ARRAY(2) {
["TID"]=> STRING(2) "40"
["TAXONOMY_TERM"]=> OBJECT(STDCLASS)#179 (8) {
["TID"]=> STRING(2) "40"
["VID"]=> STRING(1) "5"
["NAME"]=> STRING(7) "XXXXXXX"
["DESCRIPTION"]=> STRING(0) ""
["FORMAT"]=> STRING(2) "21"
["WEIGHT"]=> STRING(1) "2"
["VOCABULARY_MACHINE_NAME"]=> STRING(11) "PERSON_TYPE"
["PATH"]=> ARRAY(1) {
["PATHAUTO"]=> STRING(1) "1"
}
}
}
}
Try this field_person_type.0.taxonomy_term.name
Twig cannot access the name magically, you have to access it like you would access an array.
As the dump states: Your field (field_person_type) is an array. Inside you have [0] which is also an array with 2 entries. The "TAXONOMY_TERM" inside is an object so should be accessed as an object.
The following should give you your result
field_person_type[0]["TAXONOMY_TERM"].NAME
I have a problem with twig. I need to use nested variables such as (account is an object)
{{ likes_array.[account.idOnSn].lifetime }}
This is a result of print_r(likes_array)
array(2) {
["tanitweb"]=> array(2) {
["lifetime"]=> int(1420)
["daily"]=> int(0)
}
["fstjuniorentreprise"]=> array(2) {
["lifetime"]=> int(3310)
["daily"]=> int(3310)
}
}
I get this exception
Expected name or number in StatsDotTnMainBundle:Default:acceuil.php.twig at line 188
Use index notation, with square brackets:
{{ likes_array[account.idOnSn].lifetime }}
Hie I am trying to get the synopsis and other items like author and published date printed. But I am Able to achieve this only with certain search terms, an error occurs with other words or terms
Key "description" for array with keys "title, subtitle, authors, publishedDate, industryIdentifiers, readingModes, pageCount, printType, categories, maturityRating, allowAnonLogging, contentVersion, imageLinks, language, previewLink, infoLink, canonicalVolumeLink" does not exist.
I am using symfony and twig. this is what the twig file looks like :
{% for item in items %}
<article>
<img src="{{ item.volumeInfo.imageLinks.thumbnail}}"/>
<h4>{{ item.volumeInfo.title}}</h4>
{{ item.volumeInfo.description }}
<strong> {{ item.volumeInfo.publishedDate }}</strong><br/>
<b>{{ item.volumeInfo.authors | join }}</b>
</article>
What am I doing wrong? why does this work only sometimes ? how can I make it work correctly all the time?
class GoogleBooksController extends Controller
{
public function getVolumeAction($title)
{
$client =new client();
$response = $client- >get("https://www.googleapis.com/books/v1/volumes?q=$title");
$data=$response->json();
$items=$data['items'];
return $this->render('BookReviewBundle:GoogleBooks:volume.html.twig', array('items'=>$items
// ...
)); }
Thanks
I belive the description field is not mandatory, so you can do follow
{% if item.volumeInfo.description is defined %}
{{ item.volumeInfo.description }}
{% endif %}