I know similar questions have been asked before. I did my search, and indeed found similar topics here and here, among others. But I can't find a solution.
Let me explain.
I have a view which presents information from a content type called 'courses'. Information is presented in a table, using views-view-table.html.twig. I have tweaked that code to 'group' my results based on semester. All that works ok. All I want to do now is output an asterisk next to a course title and a respective text at the end of that semester. So I want a simple comparison (based on course title say) so I add an asterisk next to the title, and then another comparison so that I add some text at the end of the respective table for that semester.
Finally I did solve this problem, but I think my code is very ugly - there must be a better and more elegant way, that is why I turn here to get some help.
Say that when the course title is 'Programming Methodologies' I want to add a simple asterisk.
No matter how hard I try, I could not find a good way of doing that. Here is relevant kint output:
Based on this and other examples, I 've tried various stuff, but whenever I try to drill 'below' content, I always get NULL - whatever syntax I try.
I just cannot get the string 'Programming Methodologies' .. And generally I guess can't understand how to write correct syntax there. Even testing simple things like content[0] gives NULL.
Finally, thanks to this thread, and some experimentation, I managed to achieve what I want. The following code works, but seems really ugly .. I am sure there must be a better way, but I can't find. Any help is appreciated...
I post the code because I assume it will help you understand what I 'm looking for:
{% set item = content|first|first %}
{% if item|striptags|trim|replace({"\n": "", "\r\n": "", "\t": "", "\n\r": ""}) == 'Programming Methodologies'%}
(*)
{% endif %}
In a few words, I am looking for a better way to get the string value instead of using all those twig filters: content|first|first| ... |striptags|trim|replace etc.
In another piece of code, I tried to do something similar, again relying on multiple twig filters to drill the value I wanted ...
In views-view-table.html.twig comments its specified that a 'caption' variable is available. kint output of caption is:
Again I tried a lot but could not get the 'Semester: 01' value as a simple string, so I finally used the following piece of code which does work but seems really ugly to me. I would appreciate if someone could help with something better and cleaner, both for elegance but also for the understanding it will provide.
{% if caption|first|trim|striptags|replace({"\n": "", "\r\n": "", "\t": "", "\n\r": ""}) == 'Semester: 02' %}
<div style="font-size: 90%; margin-top:8px;">some text here
</div>
{% endif %}