On a custom taxonomy archive (taxonomy-strategy.php), I would like to display all custom posts that have a taxonomy called strategy.
As per the TimberTerm documentation, I am using $context['term_page'] = new TimberTerm(); and then, in taxonomy-strategy.twig:
{% for post in term_page.posts %}
{{ post.title }}
{% endfor %}
The problem is that only 10 of the posts with that taxonomy are being outputted. I have changed my reading settings to +25 posts. I have tried passing TimberTerm() parameters to to unrestrict the number of posts, but unlike get_terms or other similar functions, TimberTerm() does not accept such a parameter.
I would prefer to solve this issue on the taxonomy archive page, since the user gets here by following the term name.
I have resolved through directly through the view:
{% for post in term_page.posts('numberposts_or_args=-1') %}
{{ post.etcetc }}
{% endfor %}
where term_page is defined by $context['term_page'] = new TimberTerm();, making the term in question defined by the template hierarchy: taxonomy-[taxname].php
Related
I tried asking this question on a related thread, but it was deleted without any notification (I understand I wasn't offering a solution, but a heads up that you were deleting my post would've been helpful...I'm new here). I'm retrying here:
I have never used Timber before and have the Easy Accordion Pro plugin with a generated shortcode of "[sp_easyaccordion id="352"]" and have tried the following in my .twig template file (which lives in Themes>My Theme>templates) and all that renders is plain text [sp_easyaccordion id="352"]. Any thoughts?
{% function('do_shortcode', '[sp_easyaccordion id="352"]') %}
OR
{{ function('do_shortcode', '[sp_easyaccordion id="352"]') }}
OR
{% filter shortcodes %}
{{ wp.do_shortcode('[sp_easyaccordion id="352"]') }}
{% endfilter %}
OR
{{ wp.do_shortcode('[sp_easyaccordion id="352"]') }}
AND simply
{% filter shortcodes %} [sp_easyaccordion id="352"] {% endfilter %}
None of these worked. Please also note that I did not add anything to my function.php file...is that something I'm missing?
According to the documentation it should be:
{% filter shortcodes %}
[sp_easyaccordion id="352"]
{% endfilter %}
Otherwise you should also be able to call a function as such:
{{ function('do_shortcode', '[sp_easyaccordion id="352"]') }}
https://timber.github.io/docs/guides/functions/#function
I was wondering if someone can tell me how to hide the action links from the list view base on a status column.
More details: I have a list view in which shows a list of items, In this list I have column named status. For each record in this list in which status is set to close, I would like to hide the edit/delete and other custom actions links from the list. Is this doable? if so, how?
Thanks
A possible solution is to override just the item_actions Twig block in the list.html.twig template used by that entity. In practice, if the entity is called Order, a template like this should work:
{# app/Resources/views/easy_admin/Order/list.html.twig #}
{% extends '#EasyAdmin/default/list.html.twig' %}
{% block item_actions %}
{% if item.status != 'close' %}
{{ parent() }}
{% endif %}
{% endblock item_actions %}
I have a problem which I cannot solve. How shall I approach the following: I have a choice field with 4 different entries, which I am rendering perfectly in a select form (twig). However, I would like to show the 4 entries as 4 separate buttons. How do I change the input type of those 4? Or do I have to do anything totally different?
Thanks for your help
-AS
edit (new following question):
Alexandru, thanks for your help. That was very helpful.
I added in the fields.html.twig the following:
{% block _appbundle_action_Style_widget -%}
{% for child in form %}
<input type="button" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
{% endfor %}
{%- endblock _appbundle_action_Style_widget %}
However, when I render it it tells me that there is an array to string conversion, which somehow does not work. When I delete the widget attributes, value, and checked parts, the buttons are getting rendered without those then.
You have a few options to choose from:
You can create a new field type, let's call it "button_group", that will extend the "choice" type and write the custom Twig for it, something like this:
https://github.com/symfony/symfony/blob/2.7/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig#L95
You can use the "choice" field type with the option: expanded => true. And create a custom form template for it only for the form you need it in:
http://symfony.com/doc/current/cookbook/form/form_customization.html#what-are-form-themes
Ok I solved my problem. In order to access the value variable I have to use the following {{ child.vars.value }}. With this I can now take the variable and put it into the value tag.
Thanks for your help.
Following is how the form is rendered.
<fieldset class="properties">
{% block form_content %}
{{ form_widget(form) }}
{% endblock %}
</fieldset>
Now I can access any form field in this template, like {{ form.description }}, it's all good . But here I have a collection field in this form, let's call it collection, I have built a custom field type for this, the block template for this custom type is customCollect_widget, everything until this point is fine, but if I want to access the collection object in this widget template, I got an error saying the field name does not exist in the form object.
Here's my widget template:
{% block customCollect_widget %}
{% spaceless %}
{% for aa in form.collections %}
<div>something</div>
{% endfor %}
....
<% endblock %}
The problem, as I figured, is that the form isn't the same object that's passed to the code above. Is there any workaround to it?
Ha, I solved it. In the collection type widget template, the form variable is referencing the form field type itself, in this case, the collection type. So to loop through the collection in the widget block, you just do {% for child in form %}.
I have a xxx.html.twig file which shows a page, but when I want to refresh the page with different data and just update it with new data, I have a select and a submit button for it.
The thing is that I don't know how do I call an action in the controller which I pass parameters to from my twig and call for new data and then I render the same twig template again with new parameters.
How do I do so?
Here are a few different ways:
{{ render(app.request.baseUrl ~ '/helper/test', {"hostid2": hostid } ) }}
or
{% include 'MyCoreBundle:Helper:test.html.twig' with {"hostid2": hostid } only %}
or
{% render controller("MyCoreBundle:Helper:test", {'hostid2': hostid}) %}
Symfony 2.1:
{% render 'YourBundle:YourController:yourAction' with {'var': value} %}
Symfony 2.6+:
{{ render(controller('YourBundle:YourController:yourAction', {'var': value})) }}
And, of course, read the documentation.
I think some parts are depricated here.
To make the include work in latest Symfony 3.1.10, I solved it like this:
{% extends 'base.html.twig' %}
{% block body %}
{{ include('AppBundle:Default:inner_content.html.twig') }}
{% endblock %}
Note: include() with parentheses.
Then all the variables are included from the parent template. If you like to restrict some variables in the child template, you use with ... only (look over)