WBCE CMS Forum

WBCE CMS – Way Better Content Editing.

Du bist nicht angemeldet.

#1 12.09.2021 20:01:41

losttrip
Mitglied

[solved] NIA in code2 section - only show section if there are posts

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.

Beitrag geändert von florian (18.09.2021 07:45:27)

Offline

#2 13.09.2021 13:47:10

florian
Administrator

Re: [solved] NIA in code2 section - only show section if there are posts

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 ...

Code allein macht nicht glücklich. Jetzt spenden!

Offline

Liked by:

losttrip

#3 13.09.2021 18:15:45

losttrip
Mitglied

Re: [solved] NIA in code2 section - only show section if there are posts

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

#4 13.09.2021 18:31:57

florian
Administrator

Re: [solved] NIA in code2 section - only show section if there are posts

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)


Code allein macht nicht glücklich. Jetzt spenden!

Offline

Liked by:

losttrip

#5 13.09.2021 19:40:15

losttrip
Mitglied

Re: [solved] NIA in code2 section - only show section if there are posts

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

#6 14.09.2021 10:03:44

florian
Administrator

Re: [solved] NIA in code2 section - only show section if there are posts

{% if newsItems | length > 1 %}
	so many news
{% endif %}

Beitrag geändert von florian (14.09.2021 10:04:23)


Code allein macht nicht glücklich. Jetzt spenden!

Offline

Liked by:

losttrip

#7 17.09.2021 03:46:41

losttrip
Mitglied

Re: [solved] NIA in code2 section - only show section if there are posts

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

#8 17.09.2021 07:30:18

florian
Administrator

Re: [solved] NIA in code2 section - only show section if there are posts

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


Code allein macht nicht glücklich. Jetzt spenden!

Offline

Liked by:

losttrip

#9 17.09.2021 14:24:16

losttrip
Mitglied

Re: [solved] NIA in code2 section - only show section if there are posts

Thank you for the helpful direction.  I have some learning to do.  smile

Offline

Fußzeile des Forums

up