WBCE CMS – Way Better Content Editing.
You are not logged in.
I have a page utilizing News with Images Anywhere (code2) in a section, and I'm trying to implement this:
Headline News (pinned news always at the top - Tag=Headline) code2 section
News code2 section (all other news posts)
I have both working, but when I do not have any posts tagged as "Headline", then the Headline News section outputs the default:
Headline News
No news available yet.
followed by:
Latest News
All the news stories follow
I would like to hide the top "Headline News" section, when there are no posts tagged with "Healine"
Is this possible with NWI or NIA?
If not, I was thinking about the has_block_content module ( https://forum.wbce.org/viewtopic.php?pid=22263#p22263 ). Could there be such a function to only show a "section" if it has content?
Thank you.
Last edited by florian (18.09.2021 06:45:27)
Offline
In the display_mode_xx.htt, you can check the variable newsItems, e.g.
{% if newsItems %}
<h2>{{ lang.TXT_HEADER }}</h2>
... your code for the "Headline" tagged news output ....
{% endif %}
... your code which should always appear ...
Sorgen sind wie Nudeln: man macht sich meist zu viele.
Offline
losttrip
Works perfectly, thank you!
Is there a list anywhere of variables like this that can be checked in this way?
For instance, there have been times when I wanted to exclude certain lines from display_mode_xx.htt IF there is only 1 News post.
Or, there are times when I want to exclude or include elements AFTER the LAST News Post.
Things like that. I am happy to play around, and not have to ask for help EVERY time I want to try something, but I don't know what variables I can check for.
Offline
Look at the output of /modules/news_img_anywhere/display_mode_99.htt (e.g. set up a test environment and call NIA with the diaplay mode 99)
Sorgen sind wie Nudeln: man macht sich meist zu viele.
Offline
losttrip
Thank you, that will come in handy.
But, I was looking for a variable that I could use to test:
"IF there is more than one news post - show this line of code."
I naively tried this:
{% if newsItems > 1 %}
<hr />
{% endif %}
But of course that didn't work.
Offline
{% if newsItems | length > 1 %}
so many news
{% endif %}
Last edited by florian (14.09.2021 09:04:23)
Sorgen sind wie Nudeln: man macht sich meist zu viele.
Offline
losttrip
Thank you, that works perfectly.
Here's a naive question... are these generic php coding structures, or are they specific to WBCE and NWI (or whatever other module we might be discussing)? In other words, if I had a better grasp of PHP in general, would I be able to come up with these solutions more easily myself, or does it take more knowledge about specific coding in the module in question?
Offline
It's a combination from twig template language and module specific variables. That means, you can only use the variables which are defined in the news_img_anywhere/include.php
Sorgen sind wie Nudeln: man macht sich meist zu viele.
Offline
losttrip
Thank you for the helpful direction. I have some learning to do.
Offline